diff options
author | Eli Fidler <efidler@topologyinc.com> | 2016-05-31 21:03:07 +0300 |
---|---|---|
committer | Eli Fidler <efidler@topologyinc.com> | 2016-06-14 17:01:41 +0300 |
commit | 21acc56d578821bdf2ae8e9ec06fabe18b2f12cc (patch) | |
tree | 708fa2b3d899bf6e2e027479a20b8e5376024d36 /include/rapidjson/document.h | |
parent | c52cec7e518feb30ec01bc0a978b620f8d9462ab (diff) |
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'
Diffstat (limited to 'include/rapidjson/document.h')
-rw-r--r-- | include/rapidjson/document.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index f1857f5c..b0162f55 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<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)); return a >= b && a <= b; // Prevent -Wfloat-equal } |