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

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


http://hg.python.org/cpython/rev/b05a6a6eb525
changeset:   84701:b05a6a6eb525
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jul 18 01:12:35 2013 +0200
summary:
  Issue #18408: Fix array_tolist(), handle PyList_SetItem() failure

files:
  Modules/arraymodule.c |  15 +++++++++------
  1 files changed, 9 insertions(+), 6 deletions(-)


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

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


More information about the Python-checkins mailing list