diff options
| author | Martin Panter <vadmium+py@gmail.com> | 2016-09-07 23:31:39 (GMT) |
|---|---|---|
| committer | Martin Panter <vadmium+py@gmail.com> | 2016-09-07 23:31:39 (GMT) |
| commit | 1c748f383033df1126f2f79f051eee440ba08449 (patch) | |
| tree | dcb41f4507ff7d705cee8e6e8568da2798fa9807 /Modules/arraymodule.c | |
| parent | f3b5bcafcb75a2e350aa447ec7ad3d77a3eaee80 (diff) | |
| parent | be8da9c9906571698fe218da9e218ece500d5239 (diff) | |
| download | cpython-1c748f383033df1126f2f79f051eee440ba08449.zip cpython-1c748f383033df1126f2f79f051eee440ba08449.tar.gz cpython-1c748f383033df1126f2f79f051eee440ba08449.tar.bz2 | |
Issue #27570: Merge null pointer fixes from 3.5
Diffstat (limited to 'Modules/arraymodule.c')
| -rw-r--r-- | Modules/arraymodule.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 86a58d9..5868c52 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -740,8 +740,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; } @@ -799,9 +801,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 } @@ -821,7 +827,7 @@ array_repeat(arrayobject *a, Py_ssize_t n) np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); if (np == NULL) return NULL; - if (n == 0) + if (size == 0) return (PyObject *)np; oldbytes = Py_SIZE(a) * a->ob_descr->itemsize; newbytes = oldbytes * n; @@ -942,8 +948,10 @@ array_do_extend(arrayobject *self, PyObject *bb) size = oldsize + Py_SIZE(b); if (array_resize(self, size) == -1) return -1; - memcpy(self->ob_item + oldsize * self->ob_descr->itemsize, - b->ob_item, bbsize * b->ob_descr->itemsize); + if (bbsize > 0) { + memcpy(self->ob_item + oldsize * self->ob_descr->itemsize, + b->ob_item, bbsize * b->ob_descr->itemsize); + } return 0; #undef b |
