From ab1049c0462e760b2568ed050e62d094320481fa Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 8 Aug 2006 17:37:00 +0000 Subject: memcmp() can return values other than -1, 0, and +1 but tp_compare must not. --- Lib/test/test_types.py | 3 +++ Misc/NEWS | 2 ++ Objects/bufferobject.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index f0bdfde..83a01aa 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -233,6 +233,9 @@ print 'Buffers' try: buffer('asdf', -1) except ValueError: pass else: raise TestFailed, "buffer('asdf', -1) should raise ValueError" +cmp(buffer("abc"), buffer("def")) # used to raise a warning: tp_compare didn't return -1, 0, or 1 + +cmp(buffer('abc'), buffer('def')) try: buffer(None) except TypeError: pass diff --git a/Misc/NEWS b/Misc/NEWS index 04549b9..24b1645 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5 release candidate 1? Core and builtins ----------------- +- Bug #1536786: buffer comparison could emit a RuntimeWarning. + - Bug #1535165: fixed a segfault in input() and raw_input() when sys.stdin is closed. diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c index 588f7e2..5f3c7a9 100644 --- a/Objects/bufferobject.c +++ b/Objects/bufferobject.c @@ -272,7 +272,7 @@ buffer_compare(PyBufferObject *self, PyBufferObject *other) if (min_len > 0) { cmp = memcmp(p1, p2, min_len); if (cmp != 0) - return cmp; + return cmp < 0 ? -1 : 1; } return (len_self < len_other) ? -1 : (len_self > len_other) ? 1 : 0; } -- cgit v0.12