[Python-checkins] cpython (2.7): Backport issue #12973 list_repeat fix from 3.x.
mark.dickinson
python-checkins at python.org
Mon Sep 19 20:24:37 CEST 2011
http://hg.python.org/cpython/rev/f8280cf63d9e
changeset: 72419:f8280cf63d9e
branch: 2.7
parent: 72416:07efe83795b0
user: Mark Dickinson <mdickinson at enthought.com>
date: Mon Sep 19 19:23:55 2011 +0100
summary:
Backport issue #12973 list_repeat fix from 3.x.
files:
Misc/NEWS | 4 +++-
Objects/listobject.c | 6 +++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,7 +12,9 @@
- Issue #12973: Fix overflow checks that invoked undefined behaviour in
int.__pow__. These overflow checks were causing int.__pow__ to produce
incorrect results with recent versions of Clang, as a result of the
- compiler optimizing the check away.
+ compiler optimizing the check away. Also fix similar overflow check
+ in list_repeat (which caused test_list to fail with recent versions
+ of Clang).
- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase
titlecased and cased non-letter characters.
diff --git a/Objects/listobject.c b/Objects/listobject.c
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -58,7 +58,7 @@
if (newsize == 0)
new_allocated = 0;
items = self->ob_item;
- if (new_allocated <= ((~(size_t)0) / sizeof(PyObject *)))
+ if (new_allocated <= (PY_SIZE_MAX / sizeof(PyObject *)))
PyMem_RESIZE(items, PyObject *, new_allocated);
else
items = NULL;
@@ -551,9 +551,9 @@
PyObject *elem;
if (n < 0)
n = 0;
+ if (n > 0 && Py_SIZE(a) > PY_SSIZE_T_MAX / n)
+ return PyErr_NoMemory();
size = Py_SIZE(a) * n;
- if (n && size/n != Py_SIZE(a))
- return PyErr_NoMemory();
if (size == 0)
return PyList_New(0);
np = (PyListObject *) PyList_New(size);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list