summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_itertools.py1
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/itertoolsmodule.c8
3 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 4b631dda48..68987257d7 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -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)
diff --git a/Misc/NEWS b/Misc/NEWS
index fe3ed7994c..794ccc151f 100644
--- 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
-----
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index d91389033f..a41f55b20d 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -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;