Skip to content

Commit

Permalink
Safer casting from double to long.
Browse files Browse the repository at this point in the history
(cherry picked from commit 372e28c)
  • Loading branch information
kevinbackhouse authored and mergify-bot committed Aug 3, 2021
1 parent e7d43b9 commit 4674fae
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,24 @@ namespace Exiv2 {
}
// #55 crash when value_.at(n).first == LONG_MIN
#define LARGE_INT 1000000
// Specialization for double
template<>
inline long ValueType<double>::toLong(long n) const
{
const double v = value_.at(n);
ok_ = (INT_MIN <= v && v <= INT_MAX);
if (!ok_) return 0;
return static_cast<long>(v);
}
// Specialization for float
template<>
inline long ValueType<float>::toLong(long n) const
{
const double v = value_.at(n);
ok_ = (INT_MIN <= v && v <= INT_MAX);
if (!ok_) return 0;
return static_cast<long>(v);
}
// Specialization for rational
template<>
inline long ValueType<Rational>::toLong(long n) const
Expand Down

0 comments on commit 4674fae

Please sign in to comment.