diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-23 21:00:32 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-23 21:00:32 (GMT) |
commit | 0cc5a2b263b3783adf687f41e6f77b840a39032e (patch) | |
tree | a2f6f39d7bf81613c351c73d6c92b4703ecfb7b2 /Modules/arraymodule.c | |
parent | aaa4baf4e596d76e551becda368df33946f40c07 (diff) | |
download | cpython-0cc5a2b263b3783adf687f41e6f77b840a39032e.zip cpython-0cc5a2b263b3783adf687f41e6f77b840a39032e.tar.gz cpython-0cc5a2b263b3783adf687f41e6f77b840a39032e.tar.bz2 |
Fixed integer overflow and handled MemoryError in array.buffer_info().
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index f147115..5350759 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1067,13 +1067,25 @@ Insert a new item x into the array before position i."); 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, PyInt_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_FromSsize_t(Py_SIZE(self)); + if (v == NULL) { + Py_DECREF(retval); + return NULL; + } + PyTuple_SET_ITEM(retval, 1, v); return retval; } |