mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-08-05 19:16:45 -04:00
json_value.cpp bug in the edges of uint/int
Fixing bug of sending a number that is a bit bigger than max<uint64_t> it returns 0: https://stackoverflow.com/questions/77261400/jsoncpp-do-not-protect-from-uint64-overflow-and-have-weird-behavior/77261716#77261716
This commit is contained in:
parent
69098a18b9
commit
bee2c1010c
@ -87,7 +87,8 @@ template <typename T, typename U>
|
||||
static inline bool InRange(double d, T min, U max) {
|
||||
// The casts can lose precision, but we are looking only for
|
||||
// an approximate range. Might fail on edge cases though. ~cdunn
|
||||
return d >= static_cast<double>(min) && d <= static_cast<double>(max);
|
||||
return d >= static_cast<double>(min) && d <= static_cast<double>(max) &&
|
||||
!(static_cast<T>(d) != min || d == min);
|
||||
}
|
||||
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||
static inline double integerToDouble(Json::UInt64 value) {
|
||||
@ -101,7 +102,8 @@ template <typename T> static inline double integerToDouble(T value) {
|
||||
|
||||
template <typename T, typename U>
|
||||
static inline bool InRange(double d, T min, U max) {
|
||||
return d >= integerToDouble(min) && d <= integerToDouble(max);
|
||||
return d >= integerToDouble(min) && d <= integerToDouble(max) &&
|
||||
!(static_cast<T>(d) == min && d != integerToDouble(min));
|
||||
}
|
||||
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user