[tz] Invalid tm handling in %s pattern in strftime
Paul Eggert
eggert at cs.ucla.edu
Mon Jun 6 18:27:40 UTC 2022
On 6/6/22 10:35, Almaz Mingaleev wrote:
> 1) According to the man page mktime sets errno if tm is invalid. Why is it
> not safe to just check errno value (saving and restoring it if needed)?
Because mktime can set errno if tm is valid. mktime is like most C
syscalls - when they fail, they set errno to a value that tells you what
the error was, but when they succeed they set errno to an unspecified value.
> 2) man page says that in error case mktime "returns (time_t) -1 and does
> not alter the members of the broken-down time structure". Wouldn't it be
> enough to check that tm.tm_yday is >= 0?
That's the man page for TZDB mktime; unfortunately the C standard does
not guarantee this and strftime.c is attempting to be portable to
non-TZDB mktime.
Now that I look at the code again, I see that the heuristic was still
too trusting of non-TZDB mktime implementations, so I installed the
attached to tighten things up. It's just a heuristic, so it can still do
the wrong thing on even weirder implementations (though not TZDB).
Perhaps some day we can optimize strftime.c if we know that
TZDB-compatible mktime is being used.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Stricter-mktime-1-heuristic-in-strftime.patch
Type: text/x-patch
Size: 2168 bytes
Desc: not available
URL: <http://mm.icann.org/pipermail/tz/attachments/20220606/3d3231d6/attachment.bin>
More information about the tz
mailing list