]> granicus.if.org Git - python/commitdiff
Bug #1550714: fix SystemError from itertools.tee on negative value for n.
authorNeal Norwitz <nnorwitz@gmail.com>
Sat, 2 Sep 2006 02:58:13 +0000 (02:58 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sat, 2 Sep 2006 02:58:13 +0000 (02:58 +0000)
Needs backport to 2.5.1 and earlier.

Lib/test/test_itertools.py
Misc/NEWS
Modules/itertoolsmodule.c

index 4b631dda4809643e56018648a05e65f39b0bc6ab..68987257d75b7387cac034da261bcc6610ad6a3f 100644 (file)
@@ -371,6 +371,7 @@ class TestBasicOps(unittest.TestCase):
 
         # test values of n
         self.assertRaises(TypeError, tee, 'abc', 'invalid')
+        self.assertRaises(ValueError, tee, [], -1)
         for n in xrange(5):
             result = tee('abc', n)
             self.assertEqual(type(result), tuple)
index fe3ed7994c25a4189731fe98d65c57785685c88e..794ccc151f7d0c5773cf7b3dde298baa2bb1b3ae 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@ Extension Modules
 
 - Bug #1548092: fix curses.tparm seg fault on invalid input.
 
+- Bug #1550714: fix SystemError from itertools.tee on negative value for n.
+
 
 Tests
 -----
index d91389033ff4ec719105716ef4dafc8b0dbbd16d..a41f55b20d160671e951fa62d81bbfc020497d2c 100644 (file)
@@ -618,11 +618,15 @@ static PyTypeObject tee_type = {
 static PyObject *
 tee(PyObject *self, PyObject *args)
 {
-       int i, n=2;
+       Py_ssize_t i, n=2;
        PyObject *it, *iterable, *copyable, *result;
 
-       if (!PyArg_ParseTuple(args, "O|i", &iterable, &n))
+       if (!PyArg_ParseTuple(args, "O|n", &iterable, &n))
                return NULL;
+       if (n < 0) {
+               PyErr_SetString(PyExc_ValueError, "n must be >= 0");
+               return NULL;
+       }
        result = PyTuple_New(n);
        if (result == NULL)
                return NULL;