diff Python/bltinmodule.c @ 23421:642a453e7a2e legacy-trunk

SF bug 555042: zip() may trigger MemoryError. NOT a bugfix candidate: this is a fix to an optimization introduced in 2.3.
author Tim Peters <tim.peters@gmail.com>
date Sun, 12 May 2002 07:19:38 +0000
parents ef6e31f0cee1
children 220b98f06415
line wrap: on
line diff
--- a/Python/bltinmodule.c	Sun May 12 06:07:21 2002 +0000
+++ b/Python/bltinmodule.c	Sun May 12 07:19:38 2002 +0000
@@ -1717,13 +1717,18 @@
 	/* args must be a tuple */
 	assert(PyTuple_Check(args));
 
-	/* Guess at result length:  the shortest of the input lengths. */
+	/* Guess at result length:  the shortest of the input lengths.
+	   If some argument refuses to say, we refuse to guess too, lest
+	   an argument like xrange(sys.maxint) lead us astray.*/
 	len = -1;	/* unknown */
 	for (i = 0; i < itemsize; ++i) {
 		PyObject *item = PyTuple_GET_ITEM(args, i);
 		int thislen = PySequence_Length(item);
-		if (thislen < 0)
+		if (thislen < 0) {
 			PyErr_Clear();
+			len = -1;
+			break;
+		}
 		else if (len < 0 || thislen < len)
 			len = thislen;
 	}