diff Modules/arraymodule.c @ 87092:285d28c3620a

Issue #19437: Fix array.buffer_info(), handle PyLong_FromVoidPtr() and PyLong_FromLong() failure
author Victor Stinner <victor.stinner@gmail.com>
date Thu, 14 Nov 2013 01:27:12 +0100
parents e7f6cef7a4cc
children 2c87d3944c7a
line wrap: on
line diff
--- a/Modules/arraymodule.c	Thu Nov 14 01:26:17 2013 +0100
+++ b/Modules/arraymodule.c	Thu Nov 14 01:27:12 2013 +0100
@@ -1133,13 +1133,25 @@
 static PyObject *
 array_buffer_info(arrayobject *self, PyObject *unused)
 {
-    PyObject* retval = NULL;
+    PyObject *retval = NULL, *v;
+
     retval = PyTuple_New(2);
     if (!retval)
         return NULL;
 
-    PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
-    PyTuple_SET_ITEM(retval, 1, PyLong_FromLong((long)(Py_SIZE(self))));
+    v = PyLong_FromVoidPtr(self->ob_item);
+    if (v == NULL) {
+        Py_DECREF(retval);
+        return NULL;
+    }
+    PyTuple_SET_ITEM(retval, 0, v);
+
+    v = PyLong_FromLong((long)(Py_SIZE(self)));
+    if (v == NULL) {
+        Py_DECREF(retval);
+        return NULL;
+    }
+    PyTuple_SET_ITEM(retval, 1, v);
 
     return retval;
 }