]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in range_repr...
authorAlexey Izbyshev <izbyshev@ispras.ru>
Fri, 24 Aug 2018 04:39:45 +0000 (07:39 +0300)
committerBenjamin Peterson <benjamin@python.org>
Fri, 24 Aug 2018 04:39:45 +0000 (21:39 -0700)
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.

Objects/rangeobject.c

index 28a244e5371007a54cd7feacbe4503144f5cc582..2b00a17425a287a4ea4dca0f085d0f00a3cfa061 100644 (file)
@@ -575,11 +575,11 @@ range_repr(rangeobject *r)
     Py_ssize_t istep;
 
     /* Check for special case values for printing.  We don't always
-       need the step value.  We don't care about errors
-       (it means overflow), so clear the errors. */
+       need the step value.  We don't care about overflow. */
     istep = PyNumber_AsSsize_t(r->step, NULL);
-    if (istep != 1 || (istep == -1 && PyErr_Occurred())) {
-        PyErr_Clear();
+    if (istep == -1 && PyErr_Occurred()) {
+        assert(!PyErr_ExceptionMatches(PyExc_OverflowError));
+        return NULL;
     }
 
     if (istep == 1)