mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
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:
commit
c5cc5011ac
8 changed files with 66 additions and 15 deletions
|
@ -15196,9 +15196,13 @@ unicodeiter_setstate(unicodeiterobject *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 > PyUnicode_GET_LENGTH(it->it_seq))
|
||||
index = PyUnicode_GET_LENGTH(it->it_seq); /* iterator truncated */
|
||||
it->it_index = index;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue