diff options
author | Zackery Spytz <zspytz@gmail.com> | 2018-12-08 14:16:55 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-08 14:16:55 (GMT) |
commit | 99d56b53560b3867844472ae381fb3f858760621 (patch) | |
tree | f81865ef12567f144d7eaf3adf8b61c136945a55 /Modules/arraymodule.c | |
parent | f05df0a4b679d0acfd0b1fe6187ba2d553b37afa (diff) | |
download | cpython-99d56b53560b3867844472ae381fb3f858760621.zip cpython-99d56b53560b3867844472ae381fb3f858760621.tar.gz cpython-99d56b53560b3867844472ae381fb3f858760621.tar.bz2 |
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().
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 6a9ff3e..aa7a4fb 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; |