[Python-checkins] r60296 - python/trunk/Objects/listobject.c

guido.van.rossum python-checkins at python.org
Fri Jan 25 20:50:27 CET 2008


Author: guido.van.rossum
Date: Fri Jan 25 20:50:26 2008
New Revision: 60296
Modified:
 python/trunk/Objects/listobject.c
Log:
Rewrite the list_inline_repeat overflow check slightly differently.
Modified: python/trunk/Objects/listobject.c
==============================================================================
--- python/trunk/Objects/listobject.c	(original)
+++ python/trunk/Objects/listobject.c	Fri Jan 25 20:50:26 2008
@@ -502,7 +502,7 @@
 	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 @@
 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 @@
 		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;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /