@@ -87,7 +87,8 @@ template <typename T, typename U>
8787static inline bool InRange (double d, T min, U max) {
8888 // The casts can lose precision, but we are looking only for
8989 // an approximate range. Might fail on edge cases though. ~cdunn
90- return d >= static_cast <double >(min) && d <= static_cast <double >(max);
90+ return d >= static_cast <double >(min) && d <= static_cast <double >(max) &&
91+ !(static_cast <U>(d) == min && d != static_cast <double >(min));
9192}
9293#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
9394static inline double integerToDouble (Json::UInt64 value) {
@@ -101,7 +102,8 @@ template <typename T> static inline double integerToDouble(T value) {
101102
102103template <typename T, typename U>
103104static inline bool InRange (double d, T min, U max) {
104- return d >= integerToDouble (min) && d <= integerToDouble (max);
105+ return d >= integerToDouble (min) && d <= integerToDouble (max) &&
106+ !(static_cast <U>(d) == min && d != integerToDouble (min));
105107}
106108#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
107109
@@ -705,6 +707,11 @@ Value::Int64 Value::asInt64() const {
705707 JSON_ASSERT_MESSAGE (isInt64 (), " LargestUInt out of Int64 range" );
706708 return Int64 (value_.uint_ );
707709 case realValue:
710+ // If the double value is in proximity to minInt64, it will be rounded to
711+ // minInt64. The correct value in this scenario is indeterminable
712+ JSON_ASSERT_MESSAGE (
713+ value_.real_ != minInt64,
714+ " Double value is minInt64, precise value cannot be determined" );
708715 JSON_ASSERT_MESSAGE (InRange (value_.real_ , minInt64, maxInt64),
709716 " double out of Int64 range" );
710717 return Int64 (value_.real_ );
0 commit comments