Make Json::normalize more strict

Rounding a regular FP value can give an invalid result - check the result too.
This commit is contained in:
SChernykh
2024-07-29 17:14:21 +02:00
parent 2bb07fe633
commit f5095247e8

View File

@ -211,11 +211,13 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero)
{ {
using namespace rapidjson; using namespace rapidjson;
if (!std::isnormal(value)) { const double value_rounded = floor(value * 100.0) / 100.0;
if (!std::isnormal(value) || !std::isnormal(value_rounded)) {
return zero ? Value(0.0) : Value(kNullType); return zero ? Value(0.0) : Value(kNullType);
} }
return Value(floor(value * 100.0) / 100.0); return Value(value_rounded);
} }