This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author laszlo
Recipients laszlo
Date 2008-12-04.21:20:33
SpamBayes Score 7.654821e-12
Marked as misclassified No
Message-id <1228425636.98.0.0937158312047.issue4536@psf.upfronthosting.co.za>
In-reply-to
Content
>>> range(1.0, 0, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer

>>> range(1.0, 0, -1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: NULL result without error in PyObject_Call

The error here is that range() does not accept float arguments. However
in the second example the step argument is -1. Since -1 is also used to
indicate a integer overflow, when processing the step argument, it is
assumed that (step == -1 && PyErr_Occurred()) means that an overflow
occured.

However in this particular case, step is supposed to be -1, and the
error is a TypeError from the previous argument which is a float. The
error is then cleared and step is rounded to fit inside an integer.

        start = PyNumber_Index(start);
        stop = PyNumber_Index(stop);
        step = validate_step(step);
        if (!start || !stop || !step)
            goto Fail;

Now in the above code start is NULL, and the if statement checks for
this, and goes to Fail which return NULL. But no error condition is set
(it was cleared before) and NULL raises a SystemError.

My patch changes three things:
* In validate_step(): remove unnecessary 'step = PyNumber_Index(step)',
because this PyNumber_Index conversion is already done in the next line
by PyNumber_AsSsize_t().
* In validate_step(): don't clear the error is the result is -1. The
overflow error is already cleared by PyNumber_AsSsize_t(), and any other
errors should remain.
* In range_new(): check for NULL values before calling validate_step(),
because unlike for the other arguments where we call PyNumber_Index(),
calling validate_step() may clear the previous error.
History
Date User Action Args
2008-12-04 21:20:37laszlosetrecipients: + laszlo
2008-12-04 21:20:36laszlosetmessageid: <1228425636.98.0.0937158312047.issue4536@psf.upfronthosting.co.za>
2008-12-04 21:20:35laszlolinkissue4536 messages
2008-12-04 21:20:34laszlocreate