diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-09-22 00:29:48 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-09-22 00:29:48 (GMT) |
commit | 4d94743c28af939864e870f556f8b656fbd3b774 (patch) | |
tree | 92d6e417f15caff24e5f2d433fae20701c012068 /Modules | |
parent | 2a46658beef7de998dfcf85ca5e9ddf97f63a8bf (diff) | |
download | cpython-4d94743c28af939864e870f556f8b656fbd3b774.zip cpython-4d94743c28af939864e870f556f8b656fbd3b774.tar.gz cpython-4d94743c28af939864e870f556f8b656fbd3b774.tar.bz2 |
When range checking was added to time.strftime() a check was placed on tm_isdst
to make sure it fell within [-1, 1] just in case someone implementing
strftime() in libc was stupid enough to assume this. Turns out, though, some
OSs (e.g. zOS) are stupid enough to use values outside of this range for time
structs created by the system itself. So instead of throwing a ValueError,
tm_isdst is now normalized before being passed to strftime().
Fixes issue #6823. Thanks Robert Shapiro for diagnosing the problem and
contributing an initial patch.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/timemodule.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 2f4092d..624405e 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -464,11 +464,13 @@ time_strftime(PyObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, "day of year out of range"); return NULL; } - if (buf.tm_isdst < -1 || buf.tm_isdst > 1) { - PyErr_SetString(PyExc_ValueError, - "daylight savings flag out of range"); - return NULL; - } + /* Normalize tm_isdst just in case someone foolishly implements %Z + based on the assumption that tm_isdst falls within the range of + [-1, 1] */ + if (buf.tm_isdst < -1) + buf.tm_isdst = -1; + else if (buf.tm_isdst > 1) + buf.tm_isdst = 1; #ifdef MS_WINDOWS /* check that the format string contains only valid directives */ |