summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-12-08 14:39:37 (GMT)
committerGitHub <noreply@github.com>2018-12-08 14:39:37 (GMT)
commit25555e0fbed15f809a247c7e16ab9d0a0088f806 (patch)
treeea790ba8966889dc230ebe1f22c0321ea331e605 /Modules/arraymodule.c
parent12b9fb603eea9298c835bae5b8742db4fa52892e (diff)
downloadcpython-25555e0fbed15f809a247c7e16ab9d0a0088f806.zip
cpython-25555e0fbed15f809a247c7e16ab9d0a0088f806.tar.gz
cpython-25555e0fbed15f809a247c7e16ab9d0a0088f806.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(). (cherry picked from commit 99d56b53560b3867844472ae381fb3f858760621) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 9254af5..bc3f62d 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1499,12 +1499,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_INCREF(Py_None);
@@ -1530,8 +1536,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;