From 99d56b53560b3867844472ae381fb3f858760621 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sat, 8 Dec 2018 07:16:55 -0700 Subject: bpo-35441: Remove dead and buggy code related to PyList_SetItem(). (GH-11033) In _localemodule.c and selectmodule.c, remove dead code that would cause double decrefs if run. In addition, replace PyList_SetItem() with PyList_SET_ITEM() in cases where a new list is populated and there is no possibility of an error. In addition, check if the list changed size in the loop in array_array_fromlist(). --- Modules/arraymodule.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Modules/arraymodule.c') diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 6a9ff3ec62..aa7a4fb23c 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1544,12 +1544,18 @@ array_array_fromlist(arrayobject *self, PyObject *list) if (array_resize(self, old_size + n) == -1) return NULL; for (i = 0; i < n; i++) { - PyObject *v = PyList_GetItem(list, i); + PyObject *v = PyList_GET_ITEM(list, i); if ((*self->ob_descr->setitem)(self, Py_SIZE(self) - n + i, v) != 0) { array_resize(self, old_size); return NULL; } + if (n != PyList_GET_SIZE(list)) { + PyErr_SetString(PyExc_RuntimeError, + "list changed size during iteration"); + array_resize(self, old_size); + return NULL; + } } } Py_RETURN_NONE; @@ -1574,8 +1580,7 @@ array_array_tolist_impl(arrayobject *self) PyObject *v = getarrayitem((PyObject *)self, i); if (v == NULL) goto error; - if (PyList_SetItem(list, i, v) < 0) - goto error; + PyList_SET_ITEM(list, i, v); } return list; -- cgit v1.2.1