diff options
author | Armin Rigo <arigo@tunes.org> | 2007-10-17 18:46:37 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2007-10-17 18:46:37 (GMT) |
commit | a1e42e11d51237a949ad2568f8a097d4b442fdec (patch) | |
tree | 09c46f959fa48a8a1bc29dd2839b79d80bab673a /Objects | |
parent | 7b201162cf842485b8b2de9b6989c6ce5ec02160 (diff) | |
download | cpython-a1e42e11d51237a949ad2568f8a097d4b442fdec.zip cpython-a1e42e11d51237a949ad2568f8a097d4b442fdec.tar.gz cpython-a1e42e11d51237a949ad2568f8a097d4b442fdec.tar.bz2 |
Fix the overflow checking of list_repeat.
Introduce overflow checking into list_inplace_repeat.
Backport candidate, possibly.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index a3fa983..fb5ce82 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -499,10 +499,10 @@ list_repeat(PyListObject *a, Py_ssize_t n) if (n < 0) n = 0; size = Py_Size(a) * n; - if (size == 0) - return PyList_New(0); if (n && size/n != Py_Size(a)) return PyErr_NoMemory(); + if (size == 0) + return PyList_New(0); np = (PyListObject *) PyList_New(size); if (np == NULL) return NULL; @@ -669,7 +669,7 @@ static PyObject * list_inplace_repeat(PyListObject *self, Py_ssize_t n) { PyObject **items; - Py_ssize_t size, i, j, p; + Py_ssize_t size, i, j, p, newsize; size = PyList_GET_SIZE(self); @@ -684,7 +684,10 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n) return (PyObject *)self; } - if (list_resize(self, size*n) == -1) + newsize = size * n; + if (newsize/n != size) + return PyErr_NoMemory(); + if (list_resize(self, newsize) == -1) return NULL; p = size; |