]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in range_repr...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 24 Aug 2018 05:45:40 +0000 (01:45 -0400)
committerGitHub <noreply@github.com>
Fri, 24 Aug 2018 05:45:40 +0000 (01:45 -0400)
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.
(cherry picked from commit 7ecae3ca0bda3cacf3b0125bae0bc718a17cc071)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Objects/rangeobject.c

index 8f5fc434bd49550b65393ada5d377c1af71d87ea..2fc70cd8d7b7c5bf791d2c88dd914315d88fe5e4 100644 (file)
@@ -618,11 +618,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)