Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 131a641

Browse files
committed
Issue #11757: select.select() now raises ValueError when a negative timeout
is passed (previously, a select.error with EINVAL would be raised). Patch by Charles-François Natali.
1 parent c6a726d commit 131a641

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_select.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_error_conditions(self):
2020
self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
2121
self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
2222
self.assertRaises(TypeError, select.select, [], [], [], "not a number")
23+
self.assertRaises(ValueError, select.select, [], [], [], -1)
2324

2425
def test_returned_list_identity(self):
2526
# See issue #8329

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Core and Builtins
103103
Library
104104
-------
105105

106+
- Issue #11757: select.select() now raises ValueError when a negative timeout
107+
is passed (previously, a select.error with EINVAL would be raised). Patch
108+
by Charles-François Natali.
109+
106110
- Issue #7311: fix html.parser to accept non-ASCII attribute values.
107111

108112
- Issue #11605: email.parser.BytesFeedParser was incorrectly converting multipart

Modules/selectmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ select_select(PyObject *self, PyObject *args)
234234
"timeout period too long");
235235
return NULL;
236236
}
237+
if (timeout < 0) {
238+
PyErr_SetString(PyExc_ValueError,
239+
"timeout must be non-negative");
240+
return NULL;
241+
}
237242
seconds = (long)timeout;
238243
timeout = timeout - (double)seconds;
239244
tv.tv_sec = seconds;

0 commit comments

Comments
 (0)