bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (#24211)

Before, using the * operator to repeat a bytearray would copy data from the start of
the internal buffer (ob_bytes) and not from the start of the actual data (ob_start).
(cherry picked from commit 61d8c54f43)

Co-authored-by: Tobias Holl <TobiasHoll@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2021-04-26 12:39:51 -07:00 committed by GitHub
parent c9c1dbd253
commit d0698c676c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -1664,6 +1664,16 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
# Shouldn't raise an error
self.assertEqual(list(it), [])
def test_repeat_after_setslice(self):
# bpo-42924: * used to copy from the wrong memory location
b = bytearray(b'abc')
b[:2] = b'x'
b1 = b * 1
b3 = b * 3
self.assertEqual(b1, b'xc')
self.assertEqual(b1, b)
self.assertEqual(b3, b'xcxcxc')
class AssortedBytesTest(unittest.TestCase):
#