From: Guido van Rossum Date: Mon, 12 Feb 2001 22:03:02 +0000 (+0000) Subject: Fix core dump whenever PyList_Reverse() was called. X-Git-Tag: v2.0.1c1~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5790c1a951dd6462f8cfc7453194d39f2678508;p=thirdparty%2FPython%2Fcpython.git Fix core dump whenever PyList_Reverse() was called. 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. --- diff --git a/Objects/listobject.c b/Objects/listobject.c index b874af9f543c..a96bd420a7af 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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; }