]> granicus.if.org Git - python/commitdiff
Fix for
authorMichael W. Hudson <mwh@python.net>
Mon, 29 Jul 2002 14:35:04 +0000 (14:35 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 29 Jul 2002 14:35:04 +0000 (14:35 +0000)
[ 587875 ] crash on deleting extended slice

The array code got simpler, always a good thing!

Lib/test/test_array.py
Lib/test/test_types.py
Modules/arraymodule.c
Objects/listobject.c

index 023af9ae1604b6668a06a4b1efd942914ee0f98e..b650033292fc64574e1608db84a5725aaf1d582f 100755 (executable)
@@ -336,6 +336,9 @@ def testtype(type, example):
         a = array.array(type, range(5))
         del a[1::-2]
         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
         a = array.array(type, range(10))
         a[::2] = array.array(type, [-1]*5)
index 7efca216fe6c3bf781c8ae9e8a02a2fbd224fab7..a38eb7f7d4dd18e05a3f215468c8d6d93cd6271e 100644 (file)
@@ -405,6 +405,9 @@ vereq(a, [0,2,4])
 a = range(5)
 del a[1::-2]
 vereq(a, [0,2,3,4])
+a = range(10)
+del a[::1000]
+vereq(a, [1, 2, 3, 4, 5, 6, 7, 8, 9])
 #  assignment
 a = range(10)
 a[::2] = [-1]*5
index 8a79027d6a299200291daa670cf06f9f74ede67a..e757d9f4943222b7b2745e3b6201668f6c55c2bb 100644 (file)
@@ -1564,7 +1564,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
 
                if (value == NULL) {
                        /* delete slice */
-                       int cur, i;
+                       int cur, i, extra;
                        
                        if (slicelength <= 0)
                                return 0;
@@ -1575,16 +1575,17 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
                                step = -step;
                        }
 
-                       for (cur = start, i = 0; cur < stop; 
+                       for (cur = start, i = 0; i < slicelength - 1;
                             cur += step, i++) {
                                memmove(self->ob_item + (cur - i)*itemsize,
                                        self->ob_item + (cur + 1)*itemsize,
                                        (step - 1) * itemsize);
                        }
-                       if (self->ob_size > (start + slicelength*step)) {
-                               memmove(self->ob_item + (start + slicelength*(step - 1))*itemsize,
-                                       self->ob_item + (start + slicelength*step)*itemsize,
-                                       (self->ob_size - (start + slicelength*step))*itemsize);
+                       extra = self->ob_size - (cur + 1);
+                       if (extra > 0) {
+                               memmove(self->ob_item + (cur - i)*itemsize,
+                                       self->ob_item + (cur + 1)*itemsize,
+                                       extra*itemsize);
                        }
 
                        self->ob_size -= slicelength;
index 1aa68ed7be8e716ea77ca9d7dc5699db5284da96..9a1a6b4705e9897247ceb73cdf5fd4ee2bbcefdd 100644 (file)
@@ -1780,11 +1780,16 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
                           understand these for loops */
                        for (cur = start, i = 0;
                             cur < stop;
-                            cur += step, i++)
-                       {
+                            cur += step, i++) {
+                               int lim = step;
+
                                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_GET_ITEM(self,
                                                                cur + j + 1));