summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-26 19:40:38 (GMT)
committerGitHub <noreply@github.com>2021-04-26 19:40:38 (GMT)
commite1203e8001432a08b87b54867490beb19a694069 (patch)
tree5bb9f8b96918574665217f73998db36ec34d93c0 /Lib/test/test_bytes.py
parent081bfe4eb58e107de0a38e98c44a3253e4ed1240 (diff)
downloadcpython-e1203e8001432a08b87b54867490beb19a694069.zip
cpython-e1203e8001432a08b87b54867490beb19a694069.tar.gz
cpython-e1203e8001432a08b87b54867490beb19a694069.tar.bz2
bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (#24212)
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 61d8c54f43a7871d016f98b38f86858817d927d5) Co-authored-by: Tobias Holl <TobiasHoll@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index bbd45c7..c2ec120 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -1592,6 +1592,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):
#