Skip to content

Commit

Permalink
Fix parsing numbers which are less than 1e-308
Browse files Browse the repository at this point in the history
Overflow should check sign of exponent.
  • Loading branch information
miloyip committed Jul 30, 2014
1 parent c4f64e7 commit 808d362
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/rapidjson/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class GenericReader {
exp = s.Take() - '0';
while (s.Peek() >= '0' && s.Peek() <= '9') {
exp = exp * 10 + (s.Take() - '0');
if (exp > 308)
if (exp > 308 && !expMinus) // exp > 308 should be rare, so it should be checked first.
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell());
}
}
Expand Down
1 change: 1 addition & 0 deletions test/unittest/readertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ TEST(Reader, ParseNumberHandler) {
TEST_DOUBLE("2.22507e-308", 2.22507e-308);
TEST_DOUBLE("-1.79769e+308", -1.79769e+308);
TEST_DOUBLE("-2.22507e-308", -2.22507e-308);
TEST_DOUBLE("4.9406564584124654e-324", 4.9406564584124654e-324); // minimum denormal
TEST_DOUBLE("18446744073709551616", 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double)
TEST_DOUBLE("-9223372036854775809", -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double)

Expand Down

0 comments on commit 808d362

Please sign in to comment.