[issue14368] floattime() should not raise an exception

STINNER Victor report at bugs.python.org
Mon Mar 19 13:28:50 CET 2012


New submission from STINNER Victor <victor.stinner at gmail.com>:

floattime() raises an OSError if _PyTime_gettimeofday() returns secs=0 and usec=0. This is wrong because _PyTime_gettimeofday() cannot fail and secs=0 is valid if the current time is 0 (1970.1.1 at 12:00 UTC). Extract of _PyTime_gettimeofday() "doc":

/* Similar to POSIX gettimeofday but cannot fail.  If system gettimeofday
 * fails or is not available, fall back to lower resolution clocks.
 */
PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp);

In practice, I suppose that nobody noticed the bug because we are in 2012, not in 1969 :-) And even if you change your system clock to 1969.11.31, you may not be able to reproduce the bug because you have to call gettimeofday() exactly at midnight to get also usec=0 ...

Attached patch removes the exception.

----------
components: Library (Lib)
files: floattime.patch
keywords: patch
messages: 156334
nosy: haypo
priority: normal
severity: normal
status: open
title: floattime() should not raise an exception
versions: Python 3.3
Added file: http://bugs.python.org/file24939/floattime.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14368>
_______________________________________


More information about the Python-bugs-list mailing list