diff options
author | Kristján Valur Jónsson <sweskman@gmail.com> | 2014-03-05 15:23:07 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <sweskman@gmail.com> | 2014-03-05 15:23:07 (GMT) |
commit | c5cc5011ac33f96a8bf28e3ba088980fd5e71d7a (patch) | |
tree | 21c775f7b89e60348ed587d1bb983b2cd61e723b /Objects/bytearrayobject.c | |
parent | 25ea45db81540b8c589c65edf2564c04461b1f34 (diff) | |
parent | 25dded041fe532fcb041b6e68582bf76b4968132 (diff) | |
download | cpython-c5cc5011ac33f96a8bf28e3ba088980fd5e71d7a.zip cpython-c5cc5011ac33f96a8bf28e3ba088980fd5e71d7a.tar.gz cpython-c5cc5011ac33f96a8bf28e3ba088980fd5e71d7a.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.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 31cc4cc..5b75705 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; } |