Index: Objects/rangeobject.c =================================================================== --- Objects/rangeobject.c (revision 67537) +++ Objects/rangeobject.c (working copy) @@ -26,19 +26,16 @@ if (!step) return PyLong_FromLong(1); - step = PyNumber_Index(step); - if (step) { - Py_ssize_t istep = PyNumber_AsSsize_t(step, NULL); - if (istep == -1 && PyErr_Occurred()) { - /* Ignore OverflowError, we know the value isn't 0. */ - PyErr_Clear(); - } - else if (istep == 0) { - PyErr_SetString(PyExc_ValueError, - "range() arg 3 must not be zero"); - Py_CLEAR(step); - } + + Py_ssize_t istep = PyNumber_AsSsize_t(step, NULL); + if (istep == -1 && PyErr_Occurred()) { + Py_CLEAR(step); } + else if (istep == 0) { + PyErr_SetString(PyExc_ValueError, + "range() arg 3 must not be zero"); + Py_CLEAR(step); + } return step; } @@ -76,8 +73,11 @@ /* Convert borrowed refs to owned refs */ start = PyNumber_Index(start); stop = PyNumber_Index(stop); + if (!start || !stop) + goto Fail; + step = validate_step(step); - if (!start || !stop || !step) + if (!step) goto Fail; }