mirror of
https://github.com/python/cpython.git
synced 2025-11-13 23:46:24 +00:00
Rewrite the list_inline_repeat overflow check slightly differently.
This commit is contained in:
parent
3dbd4c536d
commit
8d5cf4ed57
1 changed files with 7 additions and 6 deletions
|
|
@ -669,11 +669,11 @@ static PyObject *
|
||||||
list_inplace_repeat(PyListObject *self, Py_ssize_t n)
|
list_inplace_repeat(PyListObject *self, Py_ssize_t n)
|
||||||
{
|
{
|
||||||
PyObject **items;
|
PyObject **items;
|
||||||
Py_ssize_t size, i, j, p, newsize;
|
Py_ssize_t size, i, j, p;
|
||||||
|
|
||||||
|
|
||||||
size = PyList_GET_SIZE(self);
|
size = PyList_GET_SIZE(self);
|
||||||
if (size == 0) {
|
if (size == 0 || n == 1) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
@ -684,10 +684,11 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
newsize = size * n;
|
if (size > SSIZE_MAX / n) {
|
||||||
if (newsize/n != size)
|
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
if (list_resize(self, newsize) == -1)
|
}
|
||||||
|
|
||||||
|
if (list_resize(self, size*n) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p = size;
|
p = size;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue