time.mktime memory access violation bug

Peter Otten __peter__ at web.de
Thu Nov 20 17:54:24 EST 2003


Bengt Richter wrote:

> What does the following sequence do on your machine? Your tests did not
> apparently exercise the daylight savings time path involved in my crash.

My (tacit, sorry) assumption was that setting daylight savings to 1 would
subtract 3600s from the Unix epoch, making it a negative value and thus
provoke the crash. But that was wrong:

>>> def d(t):
...     tpl = time.localtime(t)
...     return time.mktime(tpl[:-3] + (0, 0, 0)) - time.mktime(tpl[:-3] +
(0, 0, 1))
...
>>> d(0)
0.0

With an arbitrary summer time:

>>> d(962924461)
3600.0
>>>

> E.g.,
> 
>  >>> import time
>  >>> time.localtime(0)
>  (1969, 12, 31, 16, 0, 0, 2, 365, 0)
>  >>> time.mktime(time.localtime(0))
>  0.0
>  >>> time.mktime(time.localtime(0)[:6]+(0,0,1))
> 
> (my NT4 crashes here)
> 

For completeness:

>>> time.localtime(0)
(1970, 1, 1, 1, 0, 0, 3, 1, 0)
>>> time.mktime(time.localtime(0))
0.0
>>> time.mktime(time.localtime(0)[:6] + (0, 0, 1))
0.0
>>>

>From the docs I would expect that such a "smart" behaviour would require a
DST flag of -1.

Looking at the two zero times (UTC + x vs UTC - x hours) I wonder if an NT
machine on this side of the zero meridian would encounter the same
problems.

Peter




More information about the Python-list mailing list