diff --git a/internal/cgen/base/floatconv-submodule-code.c b/internal/cgen/base/floatconv-submodule-code.c index 557cce7f..97144ff2 100644 --- a/internal/cgen/base/floatconv-submodule-code.c +++ b/internal/cgen/base/floatconv-submodule-code.c @@ -343,9 +343,12 @@ wuffs_private_impl__high_prec_dec__parse(wuffs_private_impl__high_prec_dec* h, if (nd < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) { h->digits[nd++] = (uint8_t)(*p - '0'); dp = (int32_t)nd; - } else if ('0' != *p) { - // Long-tail non-zeroes set the truncated bit. - h->truncated = true; + } else { + dp++; + if ('0' != *p) { + // Long-tail non-zeroes set the truncated bit. + h->truncated = true; + } } } else if (*p == ((options & diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 97a940ad..a47dc39c 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -21743,9 +21743,12 @@ wuffs_private_impl__high_prec_dec__parse(wuffs_private_impl__high_prec_dec* h, if (nd < WUFFS_PRIVATE_IMPL__HPD__DIGITS_PRECISION) { h->digits[nd++] = (uint8_t)(*p - '0'); dp = (int32_t)nd; - } else if ('0' != *p) { - // Long-tail non-zeroes set the truncated bit. - h->truncated = true; + } else { + dp++; + if ('0' != *p) { + // Long-tail non-zeroes set the truncated bit. + h->truncated = true; + } } } else if (*p == ((options & diff --git a/test/c/std/json.c b/test/c/std/json.c index 7e52e951..58e8fbf6 100644 --- a/test/c/std/json.c +++ b/test/c/std/json.c @@ -1092,12 +1092,37 @@ test_wuffs_strconv_parse_number_f64_regular() { wuffs_base__make_slice_u8((uint8_t*)(void*)strs[i], strlen(strs[i])), WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS); if (r.status.repr != wuffs_base__error__bad_argument) { - RETURN_FAIL("\"%s\": have \"%s\", want \"%s\"", strs[i], - r.status.repr, wuffs_base__error__bad_argument); + RETURN_FAIL("\"%s\": have \"%s\", want \"%s\"", strs[i], r.status.repr, + wuffs_base__error__bad_argument); } } } + // Test the integer part being more than 800 digits. + { + // Initialize buf to "1222...222e-805" with 805 twos. + char buf[1024]; + buf[0] = '1'; + for (int i = 1; i < 806; i++) { + buf[i] = '2'; + } + memcpy(buf + 806, "e-805", 5); + + wuffs_base__result_f64 r = wuffs_base__parse_number_f64( + wuffs_base__make_slice_u8((uint8_t*)(void*)buf, 811), + WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS); + uint64_t have = + (r.status.repr == NULL) + ? wuffs_base__ieee_754_bit_representation__from_f64_to_u64(r.value) + : fail; + uint64_t want = wuffs_base__ieee_754_bit_representation__from_f64_to_u64( + 1.2222222222222222222222222222222222222222222222222222222222222222); + if (have != want) { + RETURN_FAIL("\"%s\": have 0x%016" PRIX64 ", want 0x%016" PRIX64, + "1222...222e-805", have, want); + } + } + return NULL; }