diff -r 568312ea04fa Lib/test/test_select.py --- a/Lib/test/test_select.py Sun Oct 14 04:17:50 2012 +0200 +++ b/Lib/test/test_select.py Sun Oct 14 13:40:08 2012 +0300 @@ -65,6 +65,16 @@ self.fail('Unexpected return values from select():', rfd, wfd, xfd) p.close() + # Issue 16230: Crash on select resized list + def test_select_mutated(self): + a = [] + class F: + def fileno(self): + del a[-1] + return sys.__stdout__.fileno() + a[:] = [F()] * 10 + self.assertEqual(select.select([], a, []), ([], a[:5], [])) + def test_main(): support.run_unittest(SelectTestCase) support.reap_children() diff -r 568312ea04fa Modules/selectmodule.c --- a/Modules/selectmodule.c Sun Oct 14 04:17:50 2012 +0200 +++ b/Modules/selectmodule.c Sun Oct 14 13:40:08 2012 +0300 @@ -84,7 +84,7 @@ { int max = -1; int index = 0; - Py_ssize_t i, len = -1; + Py_ssize_t i; PyObject* fast_seq = NULL; PyObject* o = NULL; @@ -95,9 +95,7 @@ if (!fast_seq) return -1; - len = PySequence_Fast_GET_SIZE(fast_seq); - - for (i = 0; i < len; i++) { + for (i = 0; i < PySequence_Fast_GET_SIZE(fast_seq); i++) { SOCKET v; /* any intervening fileno() calls could decr this refcnt */