]> granicus.if.org Git - python/commitdiff
Rewrite the list_inline_repeat overflow check slightly differently.
authorGuido van Rossum <guido@python.org>
Fri, 25 Jan 2008 19:42:36 +0000 (19:42 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 25 Jan 2008 19:42:36 +0000 (19:42 +0000)
Objects/listobject.c

index c0d0e090dfa239038544e661bfc9730f059db009..10b099aecbe2d92dd71d030028fd5d3e2b9e0495 100644 (file)
@@ -490,7 +490,7 @@ list_repeat(PyListObject *a, Py_ssize_t n)
        if (n && size/n != a->ob_size)
                return PyErr_NoMemory();
        if (size == 0)
-              return PyList_New(0);
+               return PyList_New(0);
        np = (PyListObject *) PyList_New(size);
        if (np == NULL)
                return NULL;
@@ -672,10 +672,11 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
                return (PyObject *)self;
        }
 
-        p = size*n;
-        if (p/n != size)
+       if (size > SSIZE_MAX / n) {
                return PyErr_NoMemory();
-       if (list_resize(self, p) == -1)
+       }
+
+       if (list_resize(self, size*n) == -1)
                return NULL;
 
        p = size;