From 9a6e62b947ebb5547ca9a164f6145a461b98d86a Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Wed, 23 Aug 2006 23:20:29 +0000 Subject: [PATCH] Fix buglet in slice assignment of bytesobjects: assigning to b[3:0] ('stop' being before 'start') would actually assign to b[0:0] (or whatever 'stop' was) --- Lib/test/test_bytes.py | 3 +++ Objects/bytesobject.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index d45ff648510..210f08ca73d 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -235,6 +235,9 @@ def test_setslice(self): b[3:5] = [3, 4, 5, 6] self.assertEqual(b, bytes(range(10))) + + b[3:0] = [42, 42, 42] + self.assertEqual(b, bytes([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9])) def test_setslice_trap(self): # This test verifies that we correctly handle assigning self diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index d6cce6d49ec..3127c9d1695 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -310,6 +310,8 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi, if (lo < 0) lo = 0; + if (hi < lo) + hi = lo; if (hi > self->ob_size) hi = self->ob_size;