summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2011-09-19 18:23:55 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2011-09-19 18:23:55 (GMT)
commit4ac5d2cda495b90c7990f9e231553fa2dca9854f (patch)
tree2938bdc235fa6236c2a1d092545c2ce8d81956a1
parentdbbed0494113ab7631777c4996a7971770f2dcc1 (diff)
downloadcpython-4ac5d2cda495b90c7990f9e231553fa2dca9854f.zip
cpython-4ac5d2cda495b90c7990f9e231553fa2dca9854f.tar.gz
cpython-4ac5d2cda495b90c7990f9e231553fa2dca9854f.tar.bz2
Backport issue #12973 list_repeat fix from 3.x.
-rw-r--r--Misc/NEWS4
-rw-r--r--Objects/listobject.c6
2 files changed, 6 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 72d7a09..30cde1d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,7 +12,9 @@ Core and Builtins
- 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
index 08f7880..f753643 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -58,7 +58,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize)
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 @@ list_repeat(PyListObject *a, Py_ssize_t n)
PyObject *elem;
if (n < 0)
n = 0;
- size = Py_SIZE(a) * n;
- if (n && size/n != Py_SIZE(a))
+ if (n > 0 && Py_SIZE(a) > PY_SSIZE_T_MAX / n)
return PyErr_NoMemory();
+ size = Py_SIZE(a) * n;
if (size == 0)
return PyList_New(0);
np = (PyListObject *) PyList_New(size);