Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b86c549

Browse files
committed
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.
1 parent 5bba231 commit b86c549

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

Objects/listobject.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,24 +1268,30 @@ PyList_Sort(PyObject *v)
12681268
return 0;
12691269
}
12701270

1271-
static PyObject *
1272-
listreverse(PyListObject *self, PyObject *args)
1271+
static void
1272+
_listreverse(PyListObject *self)
12731273
{
12741274
register PyObject **p, **q;
12751275
register PyObject *tmp;
12761276

1277-
if (!PyArg_ParseTuple(args, ":reverse"))
1278-
return NULL;
1279-
12801277
if (self->ob_size > 1) {
12811278
for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
1282-
p < q; p++, q--) {
1279+
p < q;
1280+
p++, q--)
1281+
{
12831282
tmp = *p;
12841283
*p = *q;
12851284
*q = tmp;
12861285
}
12871286
}
1288-
1287+
}
1288+
1289+
static PyObject *
1290+
listreverse(PyListObject *self, PyObject *args)
1291+
{
1292+
if (!PyArg_ParseTuple(args, ":reverse"))
1293+
return NULL;
1294+
_listreverse(self);
12891295
Py_INCREF(Py_None);
12901296
return Py_None;
12911297
}
@@ -1297,10 +1303,7 @@ PyList_Reverse(PyObject *v)
12971303
PyErr_BadInternalCall();
12981304
return -1;
12991305
}
1300-
v = listreverse((PyListObject *)v, (PyObject *)NULL);
1301-
if (v == NULL)
1302-
return -1;
1303-
Py_DECREF(v);
1306+
_listreverse((PyListObject *)v);
13041307
return 0;
13051308
}
13061309

0 commit comments

Comments
 (0)