@@ -107,10 +107,10 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
107
107
if ((start_digits == p) || ((start_digits == p - 1 ) && (*start_digits == ' .' ) )) {
108
108
return answer;
109
109
}
110
-
110
+ // digit_count is the exact number of digits.
111
111
int32_t digit_count =
112
- int32_t (p - start_digits - 1 ); // used later to guard against overflows
113
-
112
+ int32_t (p - start_digits); // used later to guard against overflows
113
+ if (exponent > 0 ) {digit_count--;}
114
114
if ((fmt & chars_format::scientific) && (p != pend) && ((' e' == *p) || (' E' == *p))) {
115
115
const char * location_of_e = p;
116
116
int64_t exp_number = 0 ; // exponential part
@@ -149,16 +149,21 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
149
149
// If we frequently had to deal with long strings of digits,
150
150
// we could extend our code by using a 128-bit integer instead
151
151
// of a 64-bit integer. However, this is uncommon.
152
- if (((digit_count >= 19 ))) { // this is uncommon
152
+ //
153
+ // We can deal with up to 19 digits.
154
+ if (((digit_count > 19 ))) { // this is uncommon
153
155
// It is possible that the integer had an overflow.
154
156
// We have to handle the case where we have 0.0000somenumber.
157
+ // We need to be mindful of the case where we only have zeroes...
158
+ // E.g., 0.000000000...000.
155
159
const char *start = start_digits;
156
- while (*start == ' 0' || (*start == ' .' )) {
160
+ while ((start != pend) && (*start == ' 0' || *start == ' .' )) {
161
+ if (*start == ' .' ) { digit_count++; } // We will subtract it again later.
157
162
start++;
158
163
}
159
- // we over-decrement by one when there is a decimal separator
164
+ // We over-decrement by one when there is a decimal separator
160
165
digit_count -= int (start - start_digits);
161
- if (digit_count >= 19 ) {
166
+ if (digit_count > 19 ) {
162
167
answer.mantissa = 0xFFFFFFFFFFFFFFFF ; // important: we don't want the mantissa to be used in a fast path uninitialized.
163
168
answer.too_many_digits = true ;
164
169
return answer;
0 commit comments