Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Calculating the length of range objects whose length is larger than PY_SIZE_MAX will now raise a ValueError instead of an OverflowError.
8 changes: 7 additions & 1 deletion 8 Objects/rangeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ compute_range_length(PyObject *start, PyObject *stop, PyObject *step)
static Py_ssize_t
range_length(rangeobject *r)
{
return PyLong_AsSsize_t(r->length);
Py_ssize_t size = PyLong_AsSsize_t(r->length);
if (size < 0 && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_Clear();
PyErr_Format(PyExc_ValueError, "Range object too large to calculate length (Overflow Error)");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyErr_Format is only valuable when using format characters :) You want PyErr_SetString here (also your lines are too long for our C style guidelines)

return -1;
}
return size;
}

static PyObject *
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.