diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-17 21:01:30 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-17 21:01:30 (GMT) |
commit | 0b142e2809b46204620bab3dc4853c241c1b7ef1 (patch) | |
tree | ac54726b0af609f9cc212415c100d4e108b029a3 /Modules/arraymodule.c | |
parent | 08a80b11adc86edb3a7eb186fc69bd27a8a9ea52 (diff) | |
download | cpython-0b142e2809b46204620bab3dc4853c241c1b7ef1.zip cpython-0b142e2809b46204620bab3dc4853c241c1b7ef1.tar.gz cpython-0b142e2809b46204620bab3dc4853c241c1b7ef1.tar.bz2 |
Issue #18408: Fix array_index(), handle getarrayitem() failure
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 1c75989..6b37cac 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -968,8 +968,13 @@ array_count(arrayobject *self, PyObject *v) Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi = getarrayitem((PyObject *)self, i); - int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi; + int cmp; + + selfi = getarrayitem((PyObject *)self, i); + if (selfi == NULL) + return NULL; + cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) count++; @@ -990,8 +995,13 @@ array_index(arrayobject *self, PyObject *v) Py_ssize_t i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi = getarrayitem((PyObject *)self, i); - int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi; + int cmp; + + selfi = getarrayitem((PyObject *)self, i); + if (selfi == NULL) + return NULL; + cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) { return PyLong_FromLong((long)i); @@ -1016,6 +1026,8 @@ 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; cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); } @@ -1028,8 +1040,13 @@ array_remove(arrayobject *self, PyObject *v) int i; for (i = 0; i < Py_SIZE(self); i++) { - PyObject *selfi = getarrayitem((PyObject *)self,i); - int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); + PyObject *selfi; + int cmp; + + selfi = getarrayitem((PyObject *)self,i); + if (selfi == NULL) + return NULL; + cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); Py_DECREF(selfi); if (cmp > 0) { if (array_ass_slice(self, i, i+1, @@ -1068,7 +1085,9 @@ array_pop(arrayobject *self, PyObject *args) PyErr_SetString(PyExc_IndexError, "pop index out of range"); return NULL; } - v = getarrayitem((PyObject *)self,i); + v = getarrayitem((PyObject *)self, i); + if (v == NULL) + return NULL; if (array_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) { Py_DECREF(v); return NULL; |