[New-bugs-announce] [issue34423] Overflow when casting from double to time_t, and_PyTime_t.

Michał Radwański report at bugs.python.org
Fri Aug 17 17:56:49 EDT 2018


New submission from Michał Radwański <lisklusownik at gmail.com>:

Code triggering bug:

import time
time.sleep(2**63 / 10**9)

Result:

ValueError: sleep length must be non-negative

The problem is with the macro that checks the range of provided double:

Line 228 of Include/pymath.h:
#define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))

The type here is _PyTime_t, which is a typedef to int64_t. 

Proposed solution is to change <= into <, since float(2**63-1) == float(2**63), and that means that none double can ever be equal to 2**63-1.

----------
components: Interpreter Core
messages: 323676
nosy: belopolsky, enedil, lemburg, vstinner
priority: normal
severity: normal
status: open
title: Overflow when casting from double to time_t, and_PyTime_t.
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34423>
_______________________________________


More information about the New-bugs-announce mailing list