From 21acc56d578821bdf2ae8e9ec06fabe18b2f12cc Mon Sep 17 00:00:00 2001 From: Eli Fidler Date: Tue, 31 May 2016 14:03:07 -0400 Subject: [PATCH] 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' --- include/rapidjson/document.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index f1857f5..b0162f5 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -978,6 +978,9 @@ public: bool IsLosslessFloat() const { if (!IsNumber()) return false; double a = GetDouble(); + if (a < static_cast(-std::numeric_limits::max()) + || a > static_cast(std::numeric_limits::max())) + return false; double b = static_cast(static_cast(a)); return a >= b && a <= b; // Prevent -Wfloat-equal }