Issue 20941: pytime.c:184 and pytime.c:218: runtime error, outside the range of representable values of type 'long' (original) (raw)

Created on 2014-03-15 21:48 by Jeffrey.Walton, last changed 2022-04-11 14:58 by admin. This issue is now closed.

| Repositories containing patches | | | | | ------------------------------------------------------------------------------------ | | | | | http://hg.python.org/cpython | | | |

Messages (8)
msg213686 - (view) Author: Jeffrey Walton (Jeffrey.Walton) * Date: 2014-03-15 21:48
pytime.c:184: runtime error: value -1e+200 is outside the range of representable values of type 'long' and pytime.c:218: runtime error: value -1e+200 is outside the range of representable values of type 'long' It appears the cast on 'intpart' is generating the finding. 'intpart' is a double. *sec = (time_t)intpart; err = intpart - (double)*sec; if (err <= -1.0 | err >= 1.0) { error_time_t_overflow(); return -1; } Shouldn't a range test based on TIME_T_MAX with an epsilon occur first?
msg213756 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-16 20:38
Hi, > pytime.c:184: runtime error: value -1e+200 is outside the range of representable values of type 'long' How did you get this warning? > Shouldn't a range test based on TIME_T_MAX with an epsilon occur first? Two lines after, the integer overflow is checked: *sec = (time_t)intpart; err = intpart - (double)*sec; if (err <= -1.0 | err >= 1.0) { error_time_t_overflow(); return -1; } And it works, example: >>> import _testcapi >>> _testcapi.pytime_object_to_time_t(-1e+200, 0) Traceback (most recent call last): File "", line 1, in OverflowError: timestamp out of range for platform time_t (where 0 means _PyTime_ROUND_DOWN)
msg213760 - (view) Author: Gareth Rees (gdr@garethrees.org) * (Python triager) Date: 2014-03-16 21:22
> How did you get this warning? This looks like runtime output from a program built using Clang/LLVM with -fsanitize=undefined. See here: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation Signed integer overflow is undefined behaviour, so by the time *sec = (time_t)intpart has been evaluated, the undefined behaviour has already happened. It is too late to check for it afterwards.
msg213910 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-17 22:59
> Shouldn't a range test based on TIME_T_MAX with an epsilon occur first? What is this constant? I don't see it in Python source code.
msg317089 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-05-19 02:03
Maybe worth checking if this is fixed due to the changes in Issue 31373 for 3.6+.
msg317090 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-19 02:20
"resolution: out of date" Is this issue fixed or not? It's still open.
msg317091 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-05-19 02:38
I don’t know; I haven’t tested it. I was anticipating that it is fixed, but perhaps I should leave the resolution alone instead?
msg317278 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-22 13:33
I close the issue as a duplicate of bpo-31373. Reopen/comment bpo-31373 if the issue is not completely fixed.
History
Date User Action Args
2022-04-11 14:58:00 admin set github: 65140
2018-05-22 13:33:25 vstinner set status: open -> closedresolution: out of date -> duplicatemessages: + stage: resolved
2018-05-19 02:38:05 martin.panter set messages: +
2018-05-19 02:20:57 vstinner set messages: +
2018-05-19 02:03:20 martin.panter set nosy: + martin.pantermessages: + resolution: out of datesuperseder: demoting floating float values to unrepresentable types is undefined behavior
2014-03-17 22:59:58 vstinner set messages: +
2014-03-16 21:22:04 gdr@garethrees.org set nosy: + gdr@garethrees.orgmessages: +
2014-03-16 20:38:57 vstinner set messages: +
2014-03-16 12:27:49 pitrou set nosy: + vstinner
2014-03-15 21:48:45 Jeffrey.Walton create