]> granicus.if.org Git - python/commitdiff
Fix buglet in slice assignment of bytesobjects: assigning to b[3:0] ('stop'
authorThomas Wouters <thomas@python.org>
Wed, 23 Aug 2006 23:20:29 +0000 (23:20 +0000)
committerThomas Wouters <thomas@python.org>
Wed, 23 Aug 2006 23:20:29 +0000 (23:20 +0000)
being before 'start') would actually assign to b[0:0] (or whatever 'stop'
was)

Lib/test/test_bytes.py
Objects/bytesobject.c

index d45ff648510d9e9bc24b3946f6a45478fa0d4a3b..210f08ca73d8e80296d36654bcf665f25912a9f1 100644 (file)
@@ -235,6 +235,9 @@ class BytesTest(unittest.TestCase):
 
         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
index d6cce6d49ec9cee38e3a3ae72685303cb767cb16..3127c9d169598ca484e55ac5d6bf65964292d65d 100644 (file)
@@ -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;