summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-02-12 22:06:02 (GMT)
committerGuido van Rossum <guido@python.org>2001-02-12 22:06:02 (GMT)
commitb86c549c7c41d5f8fa6f50ed3e58f3a1d62a1c4e (patch)
tree67c3d29a1c1fc419f7f92f1d7b5a546dc8912bde
parent5bba231d1e78b60c9886405476df92992fb4e349 (diff)
downloadcpython-b86c549c7c41d5f8fa6f50ed3e58f3a1d62a1c4e.zip
cpython-b86c549c7c41d5f8fa6f50ed3e58f3a1d62a1c4e.tar.gz
cpython-b86c549c7c41d5f8fa6f50ed3e58f3a1d62a1c4e.tar.bz2
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 now checked into the HEAD branch. Tim will check in a test case to check for this specific bug, and an assertion in PyArgs_ParseTuple() to catch similar bugs in the future.
-rw-r--r--Objects/listobject.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index f57f6fb..0087c63 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1268,24 +1268,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;
}
@@ -1297,10 +1303,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;
}