Skip to content

Commit

Permalink
range check in IsLosslessFloat to avoid undefined double->float cast
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
efidler committed Jun 1, 2016
1 parent 0d3ee63 commit 875a9e1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,8 @@ class GenericValue {
bool IsLosslessFloat() const {
if (!IsNumber()) return false;
double a = GetDouble();
if (a < static_cast<double>(-3.4028234e38f) || a > static_cast<double>(3.4028234e38f))
return false;
double b = static_cast<double>(static_cast<float>(a));
return a >= b && a <= b; // Prevent -Wfloat-equal
}
Expand Down

0 comments on commit 875a9e1

Please sign in to comment.