From 240b728d813b52a9b616b1060f8fb52837ddb0c1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 18 Jan 2023 11:16:48 +1300 Subject: [PATCH] Report an error on overflow --- include/fmt/chrono.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 680d829e..0a917d41 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2109,8 +2109,11 @@ struct formatter, epoch - std::chrono::duration_cast(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::do_format(