Fix stringcompare when strings contain null bytes.

This commit is contained in:
Guido van Rossum 1991-02-13 23:18:39 +00:00
parent 5153e5ecd7
commit 253919f3b7

View file

@ -233,8 +233,12 @@ static int
stringcompare(a, b)
stringobject *a, *b;
{
/* XXX should use memcmp on shortest size, then compare lengths */
return strcmp(a->ob_sval, b->ob_sval);
int len_a = a->ob_size, len_b = b->ob_size;
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 = {