]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix core dump whenever PyList_Reverse() was called.
authorGuido van Rossum <guido@python.org>
Mon, 12 Feb 2001 22:03:02 +0000 (22:03 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 12 Feb 2001 22:03:02 +0000 (22:03 +0000)
This fixes SF bug #132008, reported by Warren J. Hack.

The copyright for this patch (and this patch only) belongs to CNRI, as
part of the (yet to be issued) 1.6.1 release.

This is checked into the 2.0 mainenance branch!  The HEAD branch comes
next.

Objects/listobject.c

index b874af9f543cfb72e96e9ebf8ec831177268e882..a96bd420a7af84c5f43301a3306dc7d5240fc5ef 100644 (file)
@@ -1272,24 +1272,30 @@ PyList_Sort(PyObject *v)
        return 0;
 }
 
-static PyObject *
-listreverse(PyListObject *self, PyObject *args)
+static void
+_listreverse(PyListObject *self)
 {
        register PyObject **p, **q;
        register PyObject *tmp;
        
-       if (!PyArg_ParseTuple(args, ":reverse"))
-               return NULL;
-
        if (self->ob_size > 1) {
                for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
-                                               p < q; p++, q--) {
+                    p < q;
+                    p++, q--)
+               {
                        tmp = *p;
                        *p = *q;
                        *q = tmp;
                }
        }
-       
+}
+
+static PyObject *
+listreverse(PyListObject *self, PyObject *args)
+{
+       if (!PyArg_ParseTuple(args, ":reverse"))
+               return NULL;
+       _listreverse(self);
        Py_INCREF(Py_None);
        return Py_None;
 }
@@ -1301,10 +1307,7 @@ PyList_Reverse(PyObject *v)
                PyErr_BadInternalCall();
                return -1;
        }
-       v = listreverse((PyListObject *)v, (PyObject *)NULL);
-       if (v == NULL)
-               return -1;
-       Py_DECREF(v);
+       _listreverse((PyListObject *)v);
        return 0;
 }