Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 136:6523bd2954f0 legacy-trunk
Fix stringcompare when strings contain null bytes.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 13 Feb 1991 23:18:39 +0000 |
| parents | a6934380c6e7 |
| children | 853b736a6a9e |
line wrap: on
line diff
--- a/Objects/stringobject.c Fri Jan 25 13:29:53 1991 +0000 +++ b/Objects/stringobject.c Wed Feb 13 23:18:39 1991 +0000 @@ -233,8 +233,12 @@ 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 = {
