summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-09-07 11:04:41 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-09-07 11:04:41 (GMT)
commit6eec87810fcf75249cb1060424f69ef5859e3fb1 (patch)
treea22e65c1c04d94dcc3de2f46c7dd4f26701182f4 /Modules/arraymodule.c
parent68b1f708bd27eb0551c26ae3dfcece71c12d2259 (diff)
downloadcpython-6eec87810fcf75249cb1060424f69ef5859e3fb1.zip
cpython-6eec87810fcf75249cb1060424f69ef5859e3fb1.tar.gz
cpython-6eec87810fcf75249cb1060424f69ef5859e3fb1.tar.bz2
Issue #27570: Avoid zero-length memcpy() calls with null source pointers
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index fcdd46a..9819141 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -620,8 +620,10 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
if (np == NULL)
return NULL;
- memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
- (ihigh-ilow) * a->ob_descr->itemsize);
+ if (ihigh > ilow) {
+ memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
+ (ihigh-ilow) * a->ob_descr->itemsize);
+ }
return (PyObject *)np;
}
@@ -660,9 +662,13 @@ array_concat(arrayobject *a, PyObject *bb)
if (np == NULL) {
return NULL;
}
- memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
- memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
- b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ if (Py_SIZE(a) > 0) {
+ memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
+ }
+ if (Py_SIZE(b) > 0) {
+ memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
+ b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ }
return (PyObject *)np;
#undef b
}
@@ -684,6 +690,8 @@ array_repeat(arrayobject *a, Py_ssize_t n)
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL)
return NULL;
+ if (size == 0)
+ return (PyObject *)np;
p = np->ob_item;
nbytes = Py_SIZE(a) * a->ob_descr->itemsize;
for (i = 0; i < n; i++) {
@@ -838,8 +846,10 @@ array_do_extend(arrayobject *self, PyObject *bb)
PyErr_NoMemory();
return -1;
}
- memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
- b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ if (Py_SIZE(b) > 0) {
+ memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
+ b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ }
Py_SIZE(self) = size;
self->allocated = size;