]> granicus.if.org Git - python/commitdiff
Issue #11757: select.select() now raises ValueError when a negative timeout
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 9 Apr 2011 21:49:58 +0000 (23:49 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 9 Apr 2011 21:49:58 +0000 (23:49 +0200)
is passed (previously, a select.error with EINVAL would be raised).  Patch
by Charles-François Natali.

Lib/test/test_select.py
Misc/NEWS
Modules/selectmodule.c

index fe92f45145f8b7923c09cc09bf83a47730cb3394..4a13adebfda4d63c056c31c14c4751ca17c9f6bd 100644 (file)
@@ -20,6 +20,7 @@ class SelectTestCase(unittest.TestCase):
         self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
         self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
         self.assertRaises(TypeError, select.select, [], [], [], "not a number")
+        self.assertRaises(ValueError, select.select, [], [], [], -1)
 
     def test_returned_list_identity(self):
         # See issue #8329
index 2b43122be9e2f0fc7ff7dbbd8d5791dfb304636b..95e5446e3b6055efb6b1e07c338f8e85466a2090 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,10 @@ Core and Builtins
 Library
 -------
 
+- 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.
+
 - Issue #7311: fix html.parser to accept non-ASCII attribute values.
 
 - Issue #11605: email.parser.BytesFeedParser was incorrectly converting multipart
index 65e1826eba648ca28ff192ffcecb95ed8b66b3db..5aa67ddffa4838c337260e11e7b060edf40b1f73 100644 (file)
@@ -234,6 +234,11 @@ select_select(PyObject *self, PyObject *args)
                             "timeout period too long");
             return NULL;
         }
+        if (timeout < 0) {
+            PyErr_SetString(PyExc_ValueError,
+                        "timeout must be non-negative");
+            return NULL;
+        }
         seconds = (long)timeout;
         timeout = timeout - (double)seconds;
         tv.tv_sec = seconds;