From 34b54183599207632cbd8cfcd389173b4f90b8b8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 13 Jun 2019 07:25:29 -0700 Subject: [PATCH] Fix warnings --- include/fmt/chrono.h | 22 +++++++++++----------- include/fmt/format.h | 5 +---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index ff23cfba..e891b042 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -385,9 +385,9 @@ inline bool isnan(T value) { return std::isnan(value); } -template inline int to_int(T value) { - FMT_ASSERT(isnan(value) || (value >= (std::numeric_limits::min)() && - value <= (std::numeric_limits::max)()), +// Convers value to int and checks that it's in the range [0, upper). +template inline int to_int(T value, int upper) { + FMT_ASSERT(isnan(value) || (value >= 0 && value <= upper), "invalid value"); return static_cast(value); } @@ -483,9 +483,9 @@ struct chrono_formatter { std::tm time() const { auto time = std::tm(); - time.tm_hour = to_int(hour()); - time.tm_min = to_int(minute()); - time.tm_sec = to_int(second()); + time.tm_hour = to_int(hour(), 24); + time.tm_min = to_int(minute(), 60); + time.tm_sec = to_int(second(), 60); return time; } @@ -500,7 +500,7 @@ struct chrono_formatter { write_sign(); if (isnan(value)) return write_nan(); typedef typename int_traits::main_type main_type; - main_type n = to_unsigned(to_int(value)); + main_type n = to_unsigned(to_int(value, (std::numeric_limits::max)())); int num_digits = internal::count_digits(n); if (width > num_digits) out = std::fill_n(out, width - num_digits, '0'); out = format_decimal(out, n, num_digits); @@ -541,21 +541,21 @@ struct chrono_formatter { void on_24_hour(numeric_system ns) { if (ns == numeric_system::standard) return write(hour(), 2); auto time = tm(); - time.tm_hour = to_int(hour()); + time.tm_hour = to_int(hour(), 24); format_localized(time, "%OH"); } void on_12_hour(numeric_system ns) { if (ns == numeric_system::standard) return write(hour12(), 2); auto time = tm(); - time.tm_hour = to_int(hour12()); + time.tm_hour = to_int(hour12(), 12); format_localized(time, "%OI"); } void on_minute(numeric_system ns) { if (ns == numeric_system::standard) return write(minute(), 2); auto time = tm(); - time.tm_min = to_int(minute()); + time.tm_min = to_int(minute(), 60); format_localized(time, "%OM"); } @@ -570,7 +570,7 @@ struct chrono_formatter { return; } auto time = tm(); - time.tm_sec = to_int(second()); + time.tm_sec = to_int(second(), 60); format_localized(time, "%OS"); } diff --git a/include/fmt/format.h b/include/fmt/format.h index 0ed27167..3e248039 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -94,10 +95,6 @@ # endif #endif -#if FMT_SECURE_SCL -# include -#endif - #ifdef __has_builtin # define FMT_HAS_BUILTIN(x) __has_builtin(x) #else