summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-17 23:12:35 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-17 23:12:35 (GMT)
commit4755beac3cb918a64af956b3fda3ebb5ee85c96b (patch)
tree6948d34167e5dbbaec9e81aa270d10d64e2e7739
parent0b142e2809b46204620bab3dc4853c241c1b7ef1 (diff)
downloadcpython-4755beac3cb918a64af956b3fda3ebb5ee85c96b.zip
cpython-4755beac3cb918a64af956b3fda3ebb5ee85c96b.tar.gz
cpython-4755beac3cb918a64af956b3fda3ebb5ee85c96b.tar.bz2
Issue #18408: Fix array_tolist(), handle PyList_SetItem() failure
-rw-r--r--Modules/arraymodule.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 6b37cac..f5706dd 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1027,7 +1027,7 @@ array_contains(arrayobject *self, PyObject *v)
for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
if (selfi == NULL)
- return NULL;
+ return -1;
cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
}
@@ -1405,13 +1405,16 @@ array_tolist(arrayobject *self, PyObject *unused)
return NULL;
for (i = 0; i < Py_SIZE(self); i++) {
PyObject *v = getarrayitem((PyObject *)self, i);
- if (v == NULL) {
- Py_DECREF(list);
- return NULL;
- }
- PyList_SetItem(list, i, v);
+ if (v == NULL)
+ goto error;
+ if (PyList_SetItem(list, i, v) < 0)
+ goto error;
}
return list;
+
+error:
+ Py_DECREF(list);
+ return NULL;
}
PyDoc_STRVAR(tolist_doc,