diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-08-24 05:45:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-24 05:45:40 (GMT) |
commit | 902f1618388280eeeb3957b273f0ccb3df938723 (patch) | |
tree | 62553c681923ab29411a40948b3a588bb79d8c61 /Objects/rangeobject.c | |
parent | 7d470f3f24d0c091cf1da4f13695c6bb3200a713 (diff) | |
download | cpython-902f1618388280eeeb3957b273f0ccb3df938723.zip cpython-902f1618388280eeeb3957b273f0ccb3df938723.tar.gz cpython-902f1618388280eeeb3957b273f0ccb3df938723.tar.bz2 |
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.
(cherry picked from commit 7ecae3ca0bda3cacf3b0125bae0bc718a17cc071)
Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 8f5fc43..2fc70cd 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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) |