Fix overflow in tm formatter - #2564
Conversation
0a1a08e to
0465eca
Compare
|
@vitaut, review this PR please. |
vitaut
left a comment
There was a problem hiding this comment.
Thanks for the fix. Looks good overall, just a few minor comments inline.
|
|
||
| auto tm_year() const noexcept -> int { return 1900 + tm_.tm_year; } | ||
| auto tm_sec() const noexcept -> int { | ||
| FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 60, ""); |
There was a problem hiding this comment.
According to https://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html tm_sec should be in the range [0, 61] so the upper bound should be 61 here.
There was a problem hiding this comment.
It's [0..60] since C99 and C++11.
https://en.cppreference.com/w/c/chrono/tm
https://en.cppreference.com/w/cpp/chrono/c/tm
There was a problem hiding this comment.
For compatibility, I changed the interval to [0, 61].
| return tm_.tm_yday; | ||
| } | ||
|
|
||
| auto tm_hour12() const noexcept -> int { |
There was a problem hiding this comment.
I suggest merging this function into on_12_hour since it's not used anywhere else.
There was a problem hiding this comment.
The function tm_hour12 will be used in on_12_hour_time. PR #2550 (https://github.com/fmtlib/fmt/pull/2550/files#diff-5d08eff445a9a7793fbd22d873b2284f0ae69f1550aff06f673de49768bccca0R1744-R1750)
Switch internal year calculations to long long
0465eca to
75f7dd2
Compare
|
@vitaut |
|
The documentation issue looks unrelated, merged. |
…2564) Switch internal year calculations to long long
Fix possible overflow errors in
tmformatter on invalidtmvalues.