[Python-checkins] cpython (2.7): Fixed integer overflow and handled MemoryError in array.buffer_info().

serhiy.storchaka python-checkins at python.org
Thu Jun 23 17:01:04 EDT 2016


https://hg.python.org/cpython/rev/14a905f6b6c6
changeset: 102142:14a905f6b6c6
branch: 2.7
parent: 102137:c91007ab3fda
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri Jun 24 00:00:32 2016 +0300
summary:
 Fixed integer overflow and handled MemoryError in array.buffer_info().
files:
 Modules/arraymodule.c | 18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1067,13 +1067,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, 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;
 }
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /