Skip to content

Commit

Permalink
fix bad assert
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed May 29, 2019
1 parent 0ae68b0 commit 492a204
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,14 @@ inline bool isfinite(T value) {
}
template <typename T> inline int to_int(T value) {
FMT_ASSERT(!isnan(value), "nan to int conversion is UB");
FMT_ASSERT((value >= (std::numeric_limits<int>::min)() &&
value <= (std::numeric_limits<int>::max)()),
"invalid value");
if(std::numeric_limits<T>::is_signed) {
//this covers both float and integers
FMT_ASSERT(value >= (std::numeric_limits<int>::min)(),
"value is too small to fit in an int");
}
FMT_ASSERT(value <= (std::numeric_limits<int>::max)(),
"value is too large to fit in an int");

return static_cast<int>(value);
}

Expand Down

0 comments on commit 492a204

Please sign in to comment.