[ 587875 ] crash on deleting extended slice

The array code got simpler, always a good thing!
This commit is contained in:
Michael W. Hudson 2002-07-29 14:35:04 +00:00
parent 085358a3e2
commit 56796f672f
4 changed files with 21 additions and 9 deletions

View File

@ -336,6 +336,9 @@ def testtype(type, example):
a = array.array(type, range(5)) a = array.array(type, range(5))
del a[1::-2] del a[1::-2]
vereq(a, array.array(type, [0,2,3,4])) vereq(a, array.array(type, [0,2,3,4]))
a = array.array(type, range(10))
del a[::1000]
vereq(a, array.array(type, [1,2,3,4,5,6,7,8,9]))
# assignment # assignment
a = array.array(type, range(10)) a = array.array(type, range(10))
a[::2] = array.array(type, [-1]*5) a[::2] = array.array(type, [-1]*5)

View File

@ -405,6 +405,9 @@ vereq(a, [0,2,4])
a = range(5) a = range(5)
del a[1::-2] del a[1::-2]
vereq(a, [0,2,3,4]) vereq(a, [0,2,3,4])
a = range(10)
del a[::1000]
vereq(a, [1, 2, 3, 4, 5, 6, 7, 8, 9])
# assignment # assignment
a = range(10) a = range(10)
a[::2] = [-1]*5 a[::2] = [-1]*5

View File

@ -1564,7 +1564,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (value == NULL) { if (value == NULL) {
/* delete slice */ /* delete slice */
int cur, i; int cur, i, extra;
if (slicelength <= 0) if (slicelength <= 0)
return 0; return 0;
@ -1575,16 +1575,17 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
step = -step; step = -step;
} }
for (cur = start, i = 0; cur < stop; for (cur = start, i = 0; i < slicelength - 1;
cur += step, i++) { cur += step, i++) {
memmove(self->ob_item + (cur - i)*itemsize, memmove(self->ob_item + (cur - i)*itemsize,
self->ob_item + (cur + 1)*itemsize, self->ob_item + (cur + 1)*itemsize,
(step - 1) * itemsize); (step - 1) * itemsize);
} }
if (self->ob_size > (start + slicelength*step)) { extra = self->ob_size - (cur + 1);
memmove(self->ob_item + (start + slicelength*(step - 1))*itemsize, if (extra > 0) {
self->ob_item + (start + slicelength*step)*itemsize, memmove(self->ob_item + (cur - i)*itemsize,
(self->ob_size - (start + slicelength*step))*itemsize); self->ob_item + (cur + 1)*itemsize,
extra*itemsize);
} }
self->ob_size -= slicelength; self->ob_size -= slicelength;

View File

@ -1780,11 +1780,16 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
understand these for loops */ understand these for loops */
for (cur = start, i = 0; for (cur = start, i = 0;
cur < stop; cur < stop;
cur += step, i++) cur += step, i++) {
{ int lim = step;
garbage[i] = PyList_GET_ITEM(self, cur); garbage[i] = PyList_GET_ITEM(self, cur);
for (j = 0; j < step; j++) { if (cur + step >= self->ob_size) {
lim = self->ob_size - cur - 1;
}
for (j = 0; j < lim; j++) {
PyList_SET_ITEM(self, cur + j - i, PyList_SET_ITEM(self, cur + j - i,
PyList_GET_ITEM(self, PyList_GET_ITEM(self,
cur + j + 1)); cur + j + 1));