Skip to content

Commit 46e3a14

Browse files
author
thomas.wouters
committed
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) git-svn-id: http://svn.python.org/projects/python/branches/p3yk@51531 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 063ec7c commit 46e3a14

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/test/test_bytes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ def test_setslice(self):
235235

236236
b[3:5] = [3, 4, 5, 6]
237237
self.assertEqual(b, bytes(range(10)))
238+
239+
b[3:0] = [42, 42, 42]
240+
self.assertEqual(b, bytes([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
238241

239242
def test_setslice_trap(self):
240243
# This test verifies that we correctly handle assigning self

Objects/bytesobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
310310

311311
if (lo < 0)
312312
lo = 0;
313+
if (hi < lo)
314+
hi = lo;
313315
if (hi > self->ob_size)
314316
hi = self->ob_size;
315317

0 commit comments

Comments
 (0)