[issue6823] time.strftime does unnecessary range check

Richard Shapiro report at bugs.python.org
Wed Sep 2 17:40:51 CEST 2009


New submission from Richard Shapiro <rashapiro83 at gmail.com>:

in Modules/timemodule.c, in the routine time_strftime, there is a range
check on the tm_isdst field:

        if (buf.tm_isdst < -1 || buf.tm_isdst > 1) {
            PyErr_SetString(PyExc_ValueError,
                            "daylight savings flag out of range");
            return NULL;
        }

This check is incorrect, as the tm_isdst field is interpreted as less
than 0, 0, or greater than zero (see the comment at the top of the
routine, and the documentation for the strftime function).
Unfortunately, there exists at least one platform for which tm_isdst is
set to something other than -1, 0, or 1 (on IBM zOS it's apparently set
to 2 for daylight savings). This means that you can't do the obvious 
strftime(...,localtime(...)) to format a time.

The fix is to either remove the range check entirely, or else to
normalize the +1, -1, or 0. The former is preferred unless there is some
platform on which strftime doesn't do the right thing with values
outside the range of [-1,1]. 

This bug exists in 2.5.1 and 2.6.2. I haven't checked other versions.

----------
components: Library (Lib)
messages: 92170
nosy: rshapiro
severity: normal
status: open
title: time.strftime does unnecessary range check
type: behavior
versions: Python 2.5, Python 2.6

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


More information about the Python-bugs-list mailing list