mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-10 17:43:46 +02:00
Fixed a parsing bug in decodeNumber, updating the failing test cases to be
correct in the process. (The test cases incorrectly used exact integers instead of scientific notation.)
This commit is contained in:
@@ -573,8 +573,6 @@ Reader::decodeNumber( Token &token )
|
|||||||
Value::LargestUInt maxIntegerValue = isNegative ? Value::LargestUInt(-Value::minLargestInt)
|
Value::LargestUInt maxIntegerValue = isNegative ? Value::LargestUInt(-Value::minLargestInt)
|
||||||
: Value::maxLargestUInt;
|
: Value::maxLargestUInt;
|
||||||
Value::LargestUInt threshold = maxIntegerValue / 10;
|
Value::LargestUInt threshold = maxIntegerValue / 10;
|
||||||
Value::UInt lastDigitThreshold = Value::UInt( maxIntegerValue % 10 );
|
|
||||||
assert( lastDigitThreshold >=0 && lastDigitThreshold <= 9 );
|
|
||||||
Value::LargestUInt value = 0;
|
Value::LargestUInt value = 0;
|
||||||
while ( current < token.end_ )
|
while ( current < token.end_ )
|
||||||
{
|
{
|
||||||
@@ -584,10 +582,13 @@ Reader::decodeNumber( Token &token )
|
|||||||
Value::UInt digit(c - '0');
|
Value::UInt digit(c - '0');
|
||||||
if ( value >= threshold )
|
if ( value >= threshold )
|
||||||
{
|
{
|
||||||
// If the current digit is not the last one, or if it is
|
// We've hit or exceeded the max value divided by 10 (rounded down). If
|
||||||
// greater than the last digit of the maximum integer value,
|
// a) we've only just touched the limit, b) this is the last digit, and
|
||||||
// the parse the number as a double.
|
// c) it's small enough to fit in that rounding delta, we're okay.
|
||||||
if ( current != token.end_ || digit > lastDigitThreshold )
|
// Otherwise treat this number as a double to avoid overflow.
|
||||||
|
if (value > threshold ||
|
||||||
|
current != token.end_ ||
|
||||||
|
digit > maxIntegerValue % 10)
|
||||||
{
|
{
|
||||||
return decodeDouble( token );
|
return decodeDouble( token );
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
.=19000000000000000001
|
.=1.9e+19
|
||||||
|
@@ -1 +1 @@
|
|||||||
.=-9300000000000000001
|
.=-9.3e+18
|
||||||
|
1
test/data/test_real_12.expected
Normal file
1
test/data/test_real_12.expected
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.=1.844674407370955e+19
|
2
test/data/test_real_12.json
Normal file
2
test/data/test_real_12.json
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// 2^64 -> switch to double.
|
||||||
|
18446744073709551616
|
Reference in New Issue
Block a user