diff options
author | Guido van Rossum <guido@python.org> | 1991-02-13 23:18:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-02-13 23:18:39 (GMT) |
commit | 253919f3b71657fb328890326dec14e5bb3f7dd0 (patch) | |
tree | 2b5666aa77f28c5ab0c05109ad811732c90059b7 /Objects/stringobject.c | |
parent | 5153e5ecd722ff4b3a0cbf16fc2ab3eb2a3d46ef (diff) | |
download | cpython-253919f3b71657fb328890326dec14e5bb3f7dd0.zip cpython-253919f3b71657fb328890326dec14e5bb3f7dd0.tar.gz cpython-253919f3b71657fb328890326dec14e5bb3f7dd0.tar.bz2 |
Fix stringcompare when strings contain null bytes.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 1881bdf..abb3dd6 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -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 = { |