Index: Objects/listobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v retrieving revision 2.220 diff -u -r2.220 listobject.c --- Objects/listobject.c 8 Aug 2004 21:21:18 -0000 2.220 +++ Objects/listobject.c 9 Aug 2004 05:23:27 -0000 @@ -2186,9 +2186,7 @@ if (stop < 0) stop = 0; } - else if (stop > self->ob_size) - stop = self->ob_size; - for (i = start; i < stop; i++) { + for (i = start; i < stop && i < self->ob_size; i++) { int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ); if (cmp > 0) return PyInt_FromLong((long)i); Index: Lib/test/list_tests.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/list_tests.py,v retrieving revision 1.2 diff -u -r1.2 list_tests.py --- Lib/test/list_tests.py 18 Jan 2004 21:03:23 -0000 1.2 +++ Lib/test/list_tests.py 9 Aug 2004 05:23:27 -0000 @@ -311,6 +311,18 @@ self.assertRaises(ValueError, a.index, 2, 0, 4) self.assertEqual(a, self.type2test([-2, -1, 0, 1, 2])) + # Test modifying the list during index's iteration + class EvilCmp: + def __init__(self, victim): + self.victim = victim + def __eq__(self, other): + del self.victim[:] + return False + a = self.type2test() + a[:] = [EvilCmp(a) for _ in xrange(100)] + # This used to seg fault before listobject.c 2.221 + self.assertRaises(ValueError, a.index, None) + def test_reverse(self): u = self.type2test([-2, -1, 0, 1, 2]) u2 = u[:]