diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 689c908..bd072c6 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -241,6 +241,10 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n answer.truncated = true; answer.num_digits = max_digits; } + // In very rare cases, we may have fewer than 19 digits, we want to be able to reliably + // assume that all digits up to max_digit_without_overflow have been initialized. + for(uint32_t i = answer.num_digits; i < max_digit_without_overflow; i++) { answer.digits[i] = 0; } + return answer; } } // namespace fast_float diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 09917ad..d44b06d 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -149,9 +149,10 @@ struct decimal { // Moves are allowed: decimal(decimal &&) = default; decimal &operator=(decimal &&other) = default; - // Generates a mantissa by truncating to 19 digits; this function assumes - // that num_digits >= 19 (the caller is responsible for the check). + // Generates a mantissa by truncating to 19 digits. // This function should be reasonably fast. + // Note that the user is responsible to ensure that digits are + // initialized to zero when there are fewer than 19. inline uint64_t to_truncated_mantissa() { uint64_t val; // 8 first digits