Make the various iterators' "setstate" sliently and consistently clip the

index.  This avoids the possibility of setting an iterator to an invalid
state.
This commit is contained in:
Kristján Valur Jónsson 2014-03-05 13:47:57 +00:00
parent 4ca688edeb
commit 25dded041f
8 changed files with 66 additions and 15 deletions

View file

@ -2996,9 +2996,13 @@ striter_setstate(striterobject *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 > PyBytes_GET_SIZE(it->it_seq))
index = PyBytes_GET_SIZE(it->it_seq); /* iterator exhausted */
it->it_index = index;
}
Py_RETURN_NONE;
}