From f5095247e8eee96e2169036a1d27ec64d1aecc4c Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:14:21 +0200 Subject: [PATCH] Make Json::normalize more strict Rounding a regular FP value can give an invalid result - check the result too. --- src/base/io/json/Json.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index 720f75152..cb4f7911b 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -211,11 +211,13 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero) { 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 Value(floor(value * 100.0) / 100.0); + return Value(value_rounded); }