Do not let overflows in enumerate() and count() pass silently.

This commit is contained in:
Raymond Hettinger 2007-02-08 00:07:32 +00:00
parent de33c62466
commit 6d121f168c
3 changed files with 12 additions and 2 deletions

View file

@ -2073,6 +2073,11 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
count_next(countobject *lz)
{
if (lz->cnt == LONG_MAX) {
PyErr_SetString(PyExc_OverflowError,
"cannot count beyond LONG_MAX");
return NULL;
}
return PyInt_FromSsize_t(lz->cnt++);
}