summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2014-03-05 13:47:57 (GMT)
committerKristján Valur Jónsson <sweskman@gmail.com>2014-03-05 13:47:57 (GMT)
commit25dded041fe532fcb041b6e68582bf76b4968132 (patch)
tree3c70fceb3fe5ef98a17b85aa94704d20eb5a853d /Objects/bytearrayobject.c
parent4ca688edeb07de955e1ef67c11f0e327f12ffa6e (diff)
downloadcpython-25dded041fe532fcb041b6e68582bf76b4968132.zip
cpython-25dded041fe532fcb041b6e68582bf76b4968132.tar.gz
cpython-25dded041fe532fcb041b6e68582bf76b4968132.tar.bz2
Make the various iterators' "setstate" sliently and consistently clip the
index. This avoids the possibility of setting an iterator to an invalid state.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 60b2811..50667a6 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -3043,9 +3043,13 @@ bytearrayiter_setstate(bytesiterobject *it, PyObject *state)
Py_ssize_t index = PyLong_AsSsize_t(state);
if (index == -1 && PyErr_Occurred())
return NULL;
- if (index < 0)
- index = 0;
- it->it_index = index;
+ if (it->it_seq != NULL) {
+ if (index < 0)
+ index = 0;
+ else if (index > PyByteArray_GET_SIZE(it->it_seq))
+ index = PyByteArray_GET_SIZE(it->it_seq); /* iterator exhausted */
+ it->it_index = index;
+ }
Py_RETURN_NONE;
}