diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 3080252ffc6..6c9daad5597 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -130,7 +130,14 @@ range_item(rangeobject *r, int i) static int range_length(rangeobject *r) { - return r->len; +#if LONG_MAX != INT_MAX + if (r->len > INT_MAX) { + PyErr_SetString(PyExc_ValueError, + "xrange object size cannot be reported"); + return -1; + } +#endif + return (int)(r->len); } static PyObject *