[Python-checkins] cpython: Issue #18408: Fix array_index(), handle getarrayitem() failure

victor.stinner python-checkins at python.org
Thu Jul 18 01:46:18 CEST 2013


http://hg.python.org/cpython/rev/d85b0c355052
changeset:   84700:d85b0c355052
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Jul 17 23:01:30 2013 +0200
summary:
  Issue #18408: Fix array_index(), handle getarrayitem() failure

files:
  Modules/arraymodule.c |  33 ++++++++++++++++++++++++------
  1 files changed, 26 insertions(+), 7 deletions(-)


diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -968,8 +968,13 @@
     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 @@
     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 @@
 
     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 @@
     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 @@
         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;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list