[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread miss-islington


miss-islington  added the comment:


New changeset 902f1618388280eeeb3957b273f0ccb3df938723 by Miss Islington (bot) 
in branch '3.6':
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in 
range_repr() (GH-8880)
https://github.com/python/cpython/commit/902f1618388280eeeb3957b273f0ccb3df938723


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread miss-islington


miss-islington  added the comment:


New changeset d9e1abf8d36da19f074f16046c4a9b5fe54cc083 by Miss Islington (bot) 
in branch '3.7':
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in 
range_repr() (GH-8880)
https://github.com/python/cpython/commit/d9e1abf8d36da19f074f16046c4a9b5fe54cc083


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread miss-islington


Change by miss-islington :


--
pull_requests: +8367

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread Benjamin Peterson


Benjamin Peterson  added the comment:


New changeset 7ecae3ca0bda3cacf3b0125bae0bc718a17cc071 by Benjamin Peterson 
(Alexey Izbyshev) in branch 'master':
closes bpo-34468: Objects/rangeobject.c: Fix an always-false condition in 
range_repr() (GH-8880)
https://github.com/python/cpython/commit/7ecae3ca0bda3cacf3b0125bae0bc718a17cc071


--
nosy: +benjamin.peterson
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread miss-islington


Change by miss-islington :


--
pull_requests: +8366

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread Alexey Izbyshev


Alexey Izbyshev  added the comment:

Thank you, Brett, I've submitted a PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread Alexey Izbyshev


Change by Alexey Izbyshev :


--
keywords: +patch
pull_requests: +8357
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-23 Thread Brett Cannon


Brett Cannon  added the comment:

I think your second proposal sounds about right, Alexey.

--
nosy: +brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34468] An always-false condition in range_repr() from Objects/rangeobject.c

2018-08-22 Thread Alexey Izbyshev


New submission from Alexey Izbyshev :

range_repr() contains the following snippet:

/* 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. */
istep = PyNumber_AsSsize_t(r->step, NULL);
if (istep != 1 || (istep == -1 && PyErr_Occurred())) {
PyErr_Clear();
}

The second condition in 'if' statement is always false (reported by Svace 
static analyzer). Moreover, the comment is incorrect. It implies that any error 
from PyNumber_AsSsize_t() means that an overflow occurred, but according to its 
implementation and documentation, any error is guaranteed *not* to be an 
OverflowError if the second parameter is NULL (the result is clamped on 
overflow).

In practice, 'range' invariants currently guarantee that no error can occur in 
this case because 'r->step' is a subtype of int (enforced in validate_step()). 
So the 'if' statement can be replaced either with an assert:

assert(!(istep == -1 && PyErr_Occurred()))

or with a conservative check:

if (istep == -1 && PyErr_Occurred())) {
// may also add assert(!PyErr_ExceptionMatches( PyExc_OverflowError);
return NULL;
}

Suggestions are appreciated.

--
components: Interpreter Core
messages: 323912
nosy: izbyshev, ncoghlan, serhiy.storchaka
priority: normal
severity: normal
status: open
title: An always-false condition in range_repr() from Objects/rangeobject.c
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com