From: Raymond Hettinger Date: Tue, 12 May 2015 03:00:25 +0000 (-0700) Subject: Defend against a mutation during comparison X-Git-Tag: v2.7.11rc1~302^2~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3aee092ecb53b234073028e3870502713b429f12;p=thirdparty%2FPython%2Fcpython.git Defend against a mutation during comparison --- diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index d0ddb09fb159..be301a62fc62 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -244,6 +244,11 @@ heappushpop(PyObject *self, PyObject *args) return item; } + if (PyList_GET_SIZE(heap) == 0) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + returnitem = PyList_GET_ITEM(heap, 0); Py_INCREF(item); PyList_SET_ITEM(heap, 0, item);