Skip to content

Commit dd5494b

Browse files
committed
accept numbers with large exponent
1 parent 6a034f2 commit dd5494b

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

include/boost/json/basic_parser_impl.hpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,21 +2650,18 @@ parse_number(const char* p,
26502650
else
26512651
{
26522652
char const c = *cs;
2653-
if(BOOST_JSON_LIKELY(
2654-
c >= '0' && c <= '9'))
2653+
if(BOOST_JSON_LIKELY( c >= '0' && c <= '9' ))
26552654
{
2656-
if(BOOST_JSON_UNLIKELY
2655+
if(BOOST_JSON_UNLIKELY(
26572656
// 2147483647 INT_MAX
2658-
(num.exp > 214748364 || (
2659-
num.exp == 214748364 && c > '7')))
2660-
{
2661-
BOOST_STATIC_CONSTEXPR source_location loc
2662-
= BOOST_CURRENT_LOCATION;
2663-
return fail(cs.begin(), error::exponent_overflow, &loc);
2664-
}
2665-
++cs;
2666-
BOOST_IF_CONSTEXPR( !no_parsing )
2657+
num.exp > 214748364 ||
2658+
(num.exp == 214748364 && c > '7')
2659+
))
2660+
num.exp = INT_MAX;
2661+
else BOOST_IF_CONSTEXPR( !no_parsing )
26672662
num.exp = 10 * num.exp + ( c - '0' );
2663+
2664+
++cs;
26682665
continue;
26692666
}
26702667
}
@@ -2673,19 +2670,14 @@ parse_number(const char* p,
26732670
{
26742671
if (BOOST_JSON_UNLIKELY( num.bias < (INT_MIN + num.exp) ))
26752672
{
2676-
BOOST_STATIC_CONSTEXPR source_location loc
2677-
= BOOST_CURRENT_LOCATION;
2678-
return fail(cs.begin(), error::exponent_overflow, &loc);
2673+
num.bias = 0;
2674+
num.exp = INT_MAX;
26792675
}
26802676
}
2681-
else
2677+
else if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
26822678
{
2683-
if (BOOST_JSON_UNLIKELY( num.bias > (INT_MAX - num.exp) ))
2684-
{
2685-
BOOST_STATIC_CONSTEXPR source_location loc
2686-
= BOOST_CURRENT_LOCATION;
2687-
return fail(cs.begin(), error::exponent_overflow, &loc);
2688-
}
2679+
num.bias = 0;
2680+
num.exp = INT_MAX;
26892681
}
26902682
goto finish_dub;
26912683
}

test/basic_parser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ class basic_parser_test
580580
TEST_GOOD("10000000000000000000000000");
581581

582582
TEST_GOOD("0.900719925474099178 ");
583+
TEST_GOOD("0.0e2147483648");
584+
TEST_GOOD("10.0e2147483648");
585+
TEST_GOOD("0.01e-2147483648");
583586

584587
// non-significant digits
585588
TEST_GOOD("1000000000000000000000000 ");
@@ -616,7 +619,6 @@ class basic_parser_test
616619
TEST_BAD("1000000000000000000000000.e ");
617620
TEST_BAD("0.");
618621
TEST_BAD("0.0e+");
619-
TEST_BAD("0.0e2147483648");
620622
}
621623

622624
void

test/parse.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class parse_test
8989
good("[1,2,3]");
9090
good("17");
9191
bad ("[1,2,3] #");
92-
bad ("555415214748364655415E2147483646");
93-
bad ("9.88874836020e-2147483640");
9492
}
9593

9694
void

0 commit comments

Comments
 (0)