]> granicus.if.org Git - python/commitdiff
Defend against a mutation during comparison
authorRaymond Hettinger <python@rcn.com>
Tue, 12 May 2015 02:58:56 +0000 (19:58 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 12 May 2015 02:58:56 +0000 (19:58 -0700)
Modules/_heapqmodule.c

index 38bcdbe72cf1377514a8fe8e479962dd05b54ce7..04845f165aa46d893cdbfdb97eb6b66e24574931 100644 (file)
@@ -224,6 +224,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);