diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-08-31 15:48:15 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-09-01 09:55:48 +0100 |
commit | e5af77adefc981cbc253cc4c589e1fc06cf07f43 (patch) | |
tree | e7b29859d16cbf33e263815674b1569fe99af34d /gcc | |
parent | 207c507499d23f0176cbfdfe96d3cd50dec39584 (diff) | |
download | gcc-e5af77adefc981cbc253cc4c589e1fc06cf07f43.zip gcc-e5af77adefc981cbc253cc4c589e1fc06cf07f43.tar.gz gcc-e5af77adefc981cbc253cc4c589e1fc06cf07f43.tar.bz2 |
libstdc++: Fix how chrono::parse handles errors for time-of-day values
We fail to diagnose an error and extract an incorrect time for cases
like "25:59" >> parse("%H:%M", mins). The bad "25" hour value gets
ignored (on the basis that we might not care about it if trying to
extract something like a weekday or a month name), but then when we get
to the end of the function we think we have a valid time from "59" and
so the result is 00:59.
The problem is that the '__bad_h' value is used for "no hour value read
yet" as well as "bad hour value read". If we just set __h = __bad_h and
continue, we can't tell later that we read an invalid hour.
The fix is to set failbit early when we're trying to extract a
time-of-day (e.g. duration or time_point) and we encounter an invalid
hour, minute, or second value. We can still delay other error checking
to the end.
libstdc++-v3/ChangeLog:
* include/bits/chrono_io.h (_Parser::operator()): Set failbit
early if invalid values are read when _M_need & _TimeOfDay is
non-zero.
* testsuite/std/time/parse.cc: Check that "25:59" cannot be
parsed for "%H:%M".
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions