Skip to content

Commit

Permalink
Properly test for overflow
Browse files Browse the repository at this point in the history
Do not use an approximation to do this. Instead check if the result is Inf.
  • Loading branch information
abolz committed Jun 15, 2018
1 parent d83d2ba commit f5e5d47
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/rapidjson/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,6 @@ class GenericReader {
// Force double for big integer
if (useDouble) {
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
if (RAPIDJSON_UNLIKELY(d >= 1.7976931348623157e307)) // DBL_MAX / 10.0
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
d = d * 10 + (s.TakePush() - '0');
}
}
Expand Down Expand Up @@ -1702,6 +1700,12 @@ class GenericReader {
else
d = internal::StrtodNormalPrecision(d, p);

if (d == std::numeric_limits<double>::infinity()) {
// Overflow
// TODO: internal::StrtodX should report overflow (or underflow)
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
}

cont = handler.Double(minus ? -d : d);
}
else if (useNanOrInf) {
Expand Down

0 comments on commit f5e5d47

Please sign in to comment.