summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-12 20:04:41 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-12 20:04:41 (GMT)
commit809123c61f6d8c09e87d2a5e7bd0bfc9c36791d3 (patch)
tree16893e931c2cfec04380b1a929eaf74770d2a580 /Objects
parent50bbcc27e3e0e1bacb39eb9f553bcd68f9ef077a (diff)
downloadcpython-809123c61f6d8c09e87d2a5e7bd0bfc9c36791d3.zip
cpython-809123c61f6d8c09e87d2a5e7bd0bfc9c36791d3.tar.gz
cpython-809123c61f6d8c09e87d2a5e7bd0bfc9c36791d3.tar.bz2
Issue 1704621. Fix segfaults in list_repeat() and list_inplace_repeat().
The C changes aren't quite the same as the patch given there; the test is.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/listobject.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 739a571..75ba6d0 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -487,10 +487,10 @@ list_repeat(PyListObject *a, Py_ssize_t n)
if (n < 0)
n = 0;
size = a->ob_size * n;
- if (size == 0)
- return PyList_New(0);
if (n && size/n != a->ob_size)
return PyErr_NoMemory();
+ if (size == 0)
+ return PyList_New(0);
np = (PyListObject *) PyList_New(size);
if (np == NULL)
return NULL;
@@ -661,7 +661,7 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
size = PyList_GET_SIZE(self);
- if (size == 0) {
+ if (size == 0 || n == 1) {
Py_INCREF(self);
return (PyObject *)self;
}
@@ -672,7 +672,10 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
return (PyObject *)self;
}
- if (list_resize(self, size*n) == -1)
+ p = size*n;
+ if (p/n != size)
+ return PyErr_NoMemory();
+ if (list_resize(self, p) == -1)
return NULL;
p = size;
@@ -2927,4 +2930,3 @@ listreviter_len(listreviterobject *it)
return 0;
return len;
}
-