bpo-29838: Add asserts for checking results of sq_length and mq_length slots. (#700)

Negative result should be returned only when an error is set.
This commit is contained in:
Serhiy Storchaka 2017-04-16 09:21:44 +03:00 committed by GitHub
parent 026435ce49
commit 813f943c59
3 changed files with 29 additions and 11 deletions

View file

@ -5427,8 +5427,10 @@ getindex(PyObject *self, PyObject *arg)
PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence;
if (sq && sq->sq_length) {
Py_ssize_t n = (*sq->sq_length)(self);
if (n < 0)
if (n < 0) {
assert(PyErr_Occurred());
return -1;
}
i += n;
}
}