Neaten-up a bit add add missing size change check.
This commit is contained in:
parent
871620d951
commit
90e9338383
|
@ -12,9 +12,8 @@ static int
|
|||
_siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
|
||||
{
|
||||
PyObject *newitem, *parent;
|
||||
Py_ssize_t parentpos, size;
|
||||
int cmp;
|
||||
Py_ssize_t parentpos;
|
||||
Py_ssize_t size;
|
||||
|
||||
assert(PyList_Check(heap));
|
||||
size = PyList_GET_SIZE(heap);
|
||||
|
@ -355,11 +354,12 @@ static int
|
|||
_siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
|
||||
{
|
||||
PyObject *newitem, *parent;
|
||||
Py_ssize_t parentpos, size;
|
||||
int cmp;
|
||||
Py_ssize_t parentpos;
|
||||
|
||||
assert(PyList_Check(heap));
|
||||
if (pos >= PyList_GET_SIZE(heap)) {
|
||||
size = PyList_GET_SIZE(heap);
|
||||
if (pos >= size) {
|
||||
PyErr_SetString(PyExc_IndexError, "index out of range");
|
||||
return -1;
|
||||
}
|
||||
|
@ -373,6 +373,11 @@ _siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
|
|||
cmp = PyObject_RichCompareBool(parent, newitem, Py_LT);
|
||||
if (cmp == -1)
|
||||
return -1;
|
||||
if (size != PyList_GET_SIZE(heap)) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"list changed size during iteration");
|
||||
return -1;
|
||||
}
|
||||
if (cmp == 0)
|
||||
break;
|
||||
parent = PyList_GET_ITEM(heap, parentpos);
|
||||
|
|
Loading…
Reference in New Issue