Commit 7ad3d662 authored by Guido van Rossum's avatar Guido van Rossum

Fix stringcompare when strings contain null bytes.

parent 4ba1ed09
...@@ -233,8 +233,12 @@ static int ...@@ -233,8 +233,12 @@ static int
stringcompare(a, b) stringcompare(a, b)
stringobject *a, *b; stringobject *a, *b;
{ {
/* XXX should use memcmp on shortest size, then compare lengths */ int len_a = a->ob_size, len_b = b->ob_size;
return strcmp(a->ob_sval, b->ob_sval); int min_len = (len_a < len_b) ? len_a : len_b;
int cmp = memcmp(a->ob_sval, b->ob_sval, min_len);
if (cmp != 0)
return cmp;
return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
} }
static sequence_methods string_as_sequence = { static sequence_methods string_as_sequence = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment