range check in IsLosslessFloat to avoid undefined double->float cast
UBSAN gave in Value.IsLosslessFloat: include/rapidjson/document.h:981:38: runtime error: value 3.40282e+38 is outside the range of representable values of type 'float'
This commit is contained in:
parent
c52cec7e51
commit
21acc56d57
@ -978,6 +978,9 @@ public:
|
|||||||
bool IsLosslessFloat() const {
|
bool IsLosslessFloat() const {
|
||||||
if (!IsNumber()) return false;
|
if (!IsNumber()) return false;
|
||||||
double a = GetDouble();
|
double a = GetDouble();
|
||||||
|
if (a < static_cast<double>(-std::numeric_limits<float>::max())
|
||||||
|
|| a > static_cast<double>(std::numeric_limits<float>::max()))
|
||||||
|
return false;
|
||||||
double b = static_cast<double>(static_cast<float>(a));
|
double b = static_cast<double>(static_cast<float>(a));
|
||||||
return a >= b && a <= b; // Prevent -Wfloat-equal
|
return a >= b && a <= b; // Prevent -Wfloat-equal
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user