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

@ -62,6 +62,12 @@ enum_next(enumobject *en)
PyObject *result = en->en_result;
PyObject *it = en->en_sit;
if (en->en_index == LONG_MAX) {
PyErr_SetString(PyExc_OverflowError,
"enumerate() is limited to LONG_MAX items");
return NULL;
}
next_item = (*it->ob_type->tp_iternext)(it);
if (next_item == NULL)
return NULL;