diff options
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 31cc4ccebd..5b75705abf 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -3025,9 +3025,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; } |