Skip to content

Commit

Permalink
Report an error on overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 17, 2023
1 parent dfbb952 commit 240b728
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -2109,8 +2109,11 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));

if (subsecs.count() < 0) {
subsecs += std::chrono::seconds(1);
val -= std::chrono::seconds(1);
auto second = std::chrono::seconds(1);
if (epoch.count() < (Duration::min() + second).count())
FMT_THROW(format_error("duration is too small"));
subsecs += second;
val -= second;
}

return formatter<std::tm, Char>::do_format(
Expand Down

0 comments on commit 240b728

Please sign in to comment.