Skip to content

Commit 541067a

Browse files
committed
Issue #19437: Fix array.buffer_info(), handle PyLong_FromVoidPtr() and
PyLong_FromLong() failure
1 parent 804e05e commit 541067a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Modules/arraymodule.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,13 +1133,25 @@ Insert a new item x into the array before position i.");
11331133
static PyObject *
11341134
array_buffer_info(arrayobject *self, PyObject *unused)
11351135
{
1136-
PyObject* retval = NULL;
1136+
PyObject *retval = NULL, *v;
1137+
11371138
retval = PyTuple_New(2);
11381139
if (!retval)
11391140
return NULL;
11401141

1141-
PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
1142-
PyTuple_SET_ITEM(retval, 1, PyLong_FromLong((long)(Py_SIZE(self))));
1142+
v = PyLong_FromVoidPtr(self->ob_item);
1143+
if (v == NULL) {
1144+
Py_DECREF(retval);
1145+
return NULL;
1146+
}
1147+
PyTuple_SET_ITEM(retval, 0, v);
1148+
1149+
v = PyLong_FromLong((long)(Py_SIZE(self)));
1150+
if (v == NULL) {
1151+
Py_DECREF(retval);
1152+
return NULL;
1153+
}
1154+
PyTuple_SET_ITEM(retval, 1, v);
11431155

11441156
return retval;
11451157
}

0 commit comments

Comments
 (0)