From: Guido van Rossum Date: Fri, 25 Jan 2008 19:50:26 +0000 (+0000) Subject: Rewrite the list_inline_repeat overflow check slightly differently. X-Git-Tag: v2.6a1~407 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d5cf4ed5754b505d46f0d9742c9d1d04717c68d;p=thirdparty%2FPython%2Fcpython.git Rewrite the list_inline_repeat overflow check slightly differently. --- diff --git a/Objects/listobject.c b/Objects/listobject.c index 27f0a816a848..86110cb2146c 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -502,7 +502,7 @@ list_repeat(PyListObject *a, Py_ssize_t n) if (n && size/n != Py_SIZE(a)) return PyErr_NoMemory(); if (size == 0) - return PyList_New(0); + return PyList_New(0); np = (PyListObject *) PyList_New(size); if (np == NULL) return NULL; @@ -669,11 +669,11 @@ static PyObject * list_inplace_repeat(PyListObject *self, Py_ssize_t n) { PyObject **items; - Py_ssize_t size, i, j, p, newsize; + Py_ssize_t size, i, j, p; size = PyList_GET_SIZE(self); - if (size == 0) { + if (size == 0 || n == 1) { Py_INCREF(self); return (PyObject *)self; } @@ -684,10 +684,11 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n) return (PyObject *)self; } - newsize = size * n; - if (newsize/n != size) + if (size > SSIZE_MAX / n) { return PyErr_NoMemory(); - if (list_resize(self, newsize) == -1) + } + + if (list_resize(self, size*n) == -1) return NULL; p = size;