diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-12-08 06:34:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-08 06:34:49 -0800 |
| commit | 8b7d8ac09cc0f736d0c3a39d838814d7ae253021 (patch) | |
| tree | 5e80bc867b3006ae65fe88bba33b285072b7acea /Modules/arraymodule.c | |
| parent | ee2c5a8e2dcf662048dbcf4e49af9b4aaf81f7d3 (diff) | |
| download | cpython-git-8b7d8ac09cc0f736d0c3a39d838814d7ae253021.tar.gz | |
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().
(cherry picked from commit 99d56b53560b3867844472ae381fb3f858760621)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
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 900c374c58..7b4a4a3ad2 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; |
