Skip to content

Commit 7ecae3c

Browse files
Alexey Izbyshevbenjaminp
authored andcommitted
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in range_repr() (GH-8880)
Also, propagate the error from PyNumber_AsSsize_t() because we don't care only about OverflowError which is not reported if the second argument is NULL. Reported by Svace static analyzer.
1 parent 2b824b2 commit 7ecae3c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Objects/rangeobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ range_repr(rangeobject *r)
575575
Py_ssize_t istep;
576576

577577
/* Check for special case values for printing. We don't always
578-
need the step value. We don't care about errors
579-
(it means overflow), so clear the errors. */
578+
need the step value. We don't care about overflow. */
580579
istep = PyNumber_AsSsize_t(r->step, NULL);
581-
if (istep != 1 || (istep == -1 && PyErr_Occurred())) {
582-
PyErr_Clear();
580+
if (istep == -1 && PyErr_Occurred()) {
581+
assert(!PyErr_ExceptionMatches(PyExc_OverflowError));
582+
return NULL;
583583
}
584584

585585
if (istep == 1)

0 commit comments

Comments
 (0)