[3.14] GH-141312: Allow only integers to longrangeiter_setstate state (GH-141317) (GH-141559)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c1eb)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-11-15 20:30:25 +01:00 committed by GitHub
parent 21e43d5e83
commit 79c136f87b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View file

@ -1042,6 +1042,11 @@ longrangeiter_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
static PyObject *
longrangeiter_setstate(PyObject *op, PyObject *state)
{
if (!PyLong_CheckExact(state)) {
PyErr_Format(PyExc_TypeError, "state must be an int, not %T", state);
return NULL;
}
longrangeiterobject *r = (longrangeiterobject*)op;
PyObject *zero = _PyLong_GetZero(); // borrowed reference
int cmp;