summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-26 19:39:51 (GMT)
committerGitHub <noreply@github.com>2021-04-26 19:39:51 (GMT)
commitd0698c676ca1b7d34be4165a631bf4847583de76 (patch)
treecbbf1f3808028add2c1ec80ca128f2cb319a2406 /Objects
parentc9c1dbd253d70665c1fd20e6341f9a08e21f37f4 (diff)
downloadcpython-d0698c676ca1b7d34be4165a631bf4847583de76.zip
cpython-d0698c676ca1b7d34be4165a631bf4847583de76.tar.gz
cpython-d0698c676ca1b7d34be4165a631bf4847583de76.tar.bz2
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 61d8c54f43a7871d016f98b38f86858817d927d5) Co-authored-by: Tobias Holl <TobiasHoll@users.noreply.github.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 97d7796..a1aa880 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -329,6 +329,7 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
PyByteArrayObject *result;
Py_ssize_t mysize;
Py_ssize_t size;
+ const char *buf;
if (count < 0)
count = 0;
@@ -337,13 +338,14 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
return PyErr_NoMemory();
size = mysize * count;
result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size);
+ buf = PyByteArray_AS_STRING(self);
if (result != NULL && size != 0) {
if (mysize == 1)
- memset(result->ob_bytes, self->ob_bytes[0], size);
+ memset(result->ob_bytes, buf[0], size);
else {
Py_ssize_t i;
for (i = 0; i < count; i++)
- memcpy(result->ob_bytes + i*mysize, self->ob_bytes, mysize);
+ memcpy(result->ob_bytes + i*mysize, buf, mysize);
}
}
return (PyObject *)result;