Properly test for overflow

Do not use an approximation to do this. Instead check if the result is Inf.
This commit is contained in:
abolz 2018-06-15 11:29:48 +02:00
parent d83d2ba260
commit f5e5d47fac

View File

@ -1561,8 +1561,6 @@ private:
// 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');
}
}
@ -1702,6 +1700,12 @@ private:
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) {