summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-09-02 02:58:13 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-09-02 02:58:13 (GMT)
commit69e88975059b0c74e3e9a17dd46b715a532cfd20 (patch)
tree5d38c338f3b28f72896abcac26870cbd83afc848 /Modules/itertoolsmodule.c
parent6aefa916a96f7d3ce7f634134dba6060c68b647a (diff)
downloadcpython-69e88975059b0c74e3e9a17dd46b715a532cfd20.zip
cpython-69e88975059b0c74e3e9a17dd46b715a532cfd20.tar.gz
cpython-69e88975059b0c74e3e9a17dd46b715a532cfd20.tar.bz2
Bug #1550714: fix SystemError from itertools.tee on negative value for n.
Needs backport to 2.5.1 and earlier.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index d913890..a41f55b 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;