summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_range.py12
-rw-r--r--Objects/rangeobject.c2
2 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_range.py b/Lib/test/test_range.py
index d9d4cf8..64b6a77 100644
--- a/Lib/test/test_range.py
+++ b/Lib/test/test_range.py
@@ -380,6 +380,18 @@ class RangeTest(unittest.TestCase):
it = pickle.loads(d)
self.assertEqual(list(it), data[1:])
+ def test_exhausted_iterator_pickling(self):
+ r = range(20)
+ i = iter(r)
+ while True:
+ r = next(i)
+ if r == 19:
+ break
+ d = pickle.dumps(i)
+ i2 = pickle.loads(d)
+ self.assertEqual(list(i), [])
+ self.assertEqual(list(i2), [])
+
def test_odd_bug(self):
# This used to raise a "SystemError: NULL result without error"
# because the range validation step was eating the exception
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index a4d9fb3..e82ebf44 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -807,7 +807,7 @@ rangeiter_setstate(rangeiterobject *r, PyObject *state)
long index = PyLong_AsLong(state);
if (index == -1 && PyErr_Occurred())
return NULL;
- if (index < 0 || index >= r->len) {
+ if (index < 0 || index > r->len) {
PyErr_SetString(PyExc_ValueError, "index out of range");
return NULL;
}