mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
SF patch #1005778, Fix seg fault if list object is modified during list.index()
Backport candidate
This commit is contained in:
parent
39689c5c6a
commit
f076953eb1
3 changed files with 17 additions and 3 deletions
|
|
@ -311,6 +311,18 @@ class CommonTest(seq_tests.CommonTest):
|
|||
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 patch #1005778
|
||||
self.assertRaises(ValueError, a.index, None)
|
||||
|
||||
def test_reverse(self):
|
||||
u = self.type2test([-2, -1, 0, 1, 2])
|
||||
u2 = u[:]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue