This commit is contained in:
Cameron Druyor 2016-05-08 14:19:17 +00:00
commit 864fb58bf7
3 changed files with 390 additions and 745 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6152,10 +6152,7 @@ class basic_json
// remove '+' sign from the exponent if necessary // remove '+' sign from the exponent if necessary
if (not m_type.bits.exp_plus) if (not m_type.bits.exp_plus)
{ {
if (len > static_cast<int>(sizeof(buf))) len = std::min(len, static_cast<int>(sizeof(buf)));
{
len = sizeof(buf);
}
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
{ {
if (buf[i] == '+') if (buf[i] == '+')
@ -7732,10 +7729,9 @@ class basic_json
// remember this number was parsed (for later serialization) // remember this number was parsed (for later serialization)
result.m_type.bits.parsed = true; result.m_type.bits.parsed = true;
// 'found_radix_point' will be set to 0xFF upon finding a radix // 'found_radix_point' will be set to true upon finding a radix
// point and later used to mask in/out the precision depending // point. if it is not found, then the precision will be updated
// whether a radix is found i.e. 'precision &= found_radix_point' bool found_radix_point = false;
uint8_t found_radix_point = 0;
uint8_t precision = 0; uint8_t precision = 0;
// accumulate the integer conversion result (unsigned for now) // accumulate the integer conversion result (unsigned for now)
@ -7773,7 +7769,7 @@ class basic_json
// reset precision count // reset precision count
precision = 0; precision = 0;
found_radix_point = 0xFF; found_radix_point = true;
continue; continue;
} }
// assume exponent (if not then will fail parse): change to // assume exponent (if not then will fail parse): change to
@ -7811,8 +7807,21 @@ class basic_json
} }
// If no radix point was found then precision would now be set to // If no radix point was found then precision would now be set to
// the number of digits, which is wrong - clear it. // the number of digits, which is wrong - decrement it to sig figs - 1
result.m_type.bits.precision = precision & found_radix_point; if(not found_radix_point)
{
int trailing_zeros = 0;
for (int j = precision-1;j>=0;--j)
{
auto c = *(m_start+j);
if(c == '0')
++trailing_zeros;
else if((c > '0' and c <= '9') or c == '-')
break;
}
precision -= (trailing_zeros + 1);
}
result.m_type.bits.precision = precision;
// save the value (if not a float) // save the value (if not a float)
if (type == value_t::number_unsigned) if (type == value_t::number_unsigned)

View File

@ -13951,7 +13951,9 @@ TEST_CASE("regression tests")
json j2a = 2342e-2; json j2a = 2342e-2;
//issue #230 //issue #230
//json j2b = json::parse("2342e-2"); json j2b = json::parse("2342e-2");
//diabolical version
json j2c = json::parse("234200e-4");
json j3a = 10E3; json j3a = 10E3;
json j3b = json::parse("10E3"); json j3b = json::parse("10E3");
@ -13975,7 +13977,8 @@ TEST_CASE("regression tests")
CHECK(j2a.dump() == "23.42"); CHECK(j2a.dump() == "23.42");
//issue #230 //issue #230
//CHECK(j2b.dump() == "23.42"); CHECK(j2b.dump() == "2.342e01");
CHECK(j2c.dump() == "2.342e01");
CHECK(j3a.dump() == "10000"); CHECK(j3a.dump() == "10000");
CHECK(j3b.dump() == "1E04"); CHECK(j3b.dump() == "1E04");
@ -13992,6 +13995,7 @@ TEST_CASE("regression tests")
CHECK(dest == expected); CHECK(dest == expected);
} }
} }
// special test case to check if memory is leaked if constructor throws // special test case to check if memory is leaked if constructor throws