summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-11-30 03:09:05 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-11-30 03:09:05 (GMT)
commit101f09e72f821bf153de0a3b8d361b9005a124da (patch)
treee7b38903c0966109dba1aa9af2195a851e17c350 /Modules/itertoolsmodule.c
parentfdb32c15e4c5ab924b7f547c803befa58c2a490f (diff)
downloadcpython-101f09e72f821bf153de0a3b8d361b9005a124da.zip
cpython-101f09e72f821bf153de0a3b8d361b9005a124da.tar.gz
cpython-101f09e72f821bf153de0a3b8d361b9005a124da.tar.bz2
Issue #10323: Predictable final state for slice().
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index ba8d6df..d5336f2 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1215,6 +1215,7 @@ islice_next(isliceobject *lz)
{
PyObject *item;
PyObject *it = lz->it;
+ Py_ssize_t stop = lz->stop;
Py_ssize_t oldnext;
PyObject *(*iternext)(PyObject *);
@@ -1226,7 +1227,7 @@ islice_next(isliceobject *lz)
Py_DECREF(item);
lz->cnt++;
}
- if (lz->stop != -1 && lz->cnt >= lz->stop)
+ if (stop != -1 && lz->cnt >= stop)
return NULL;
item = iternext(it);
if (item == NULL)
@@ -1234,8 +1235,8 @@ islice_next(isliceobject *lz)
lz->cnt++;
oldnext = lz->next;
lz->next += lz->step;
- if (lz->next < oldnext) /* Check for overflow */
- lz->next = lz->stop;
+ if (lz->next < oldnext || (stop != -1 && lz->next > stop))
+ lz->next = stop;
return item;
}