Safer casting from double to long.

(cherry picked from commit 372e28c41044a9e8b65d7d7093e028e30a7c8c8a)
main
Kevin Backhouse 4 years ago committed by mergify-bot
parent e7d43b94a3
commit 4674fae4ef

@ -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

Loading…
Cancel
Save