Skip to content

Commit 679e586

Browse files
committed
Added handling for scientific notation when there are no decimals
1 parent dfa260b commit 679e586

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static bool bc_scientific_notation_str2num(
109109
bc_num *num, const char *str, const char *end, const char *integer_ptr, const char *fractional_ptr, const char *exponent_ptr,
110110
size_t digits, size_t *full_scale)
111111
{
112-
const char *fractional_end = exponent_ptr;
112+
const char *fractional_end = fractional_ptr != NULL ? exponent_ptr : NULL;
113113

114114
if (UNEXPECTED(*exponent_ptr != 'e' && *exponent_ptr != 'E')) {
115115
goto fail;
@@ -173,7 +173,9 @@ static bool bc_scientific_notation_str2num(
173173
}
174174

175175
nptr = bc_copy_and_toggle_bcd(nptr, integer_ptr, integer_end);
176-
nptr = bc_copy_and_toggle_bcd(nptr, fractional_ptr, fractional_end);
176+
if (fractional_ptr != NULL) {
177+
nptr = bc_copy_and_toggle_bcd(nptr, fractional_ptr, fractional_end);
178+
}
177179

178180
if (digits > str_full_len) {
179181
/* Fill the rest integer part with zeros */
@@ -222,7 +224,7 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, siz
222224

223225
/* If a non-digit and non-decimal-point indicator is in the string, i.e. an invalid character */
224226
if (UNEXPECTED(!decimal_point && *ptr != '\0')) {
225-
goto fail;
227+
return bc_scientific_notation_str2num(num, str, end, integer_ptr, fractional_ptr, ptr, digits, full_scale);
226228
}
227229

228230
/* search and validate fractional end if exists */
@@ -311,8 +313,4 @@ bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, siz
311313
zero:
312314
*num = bc_copy_num(BCG(_zero_));
313315
return true;
314-
315-
fail:
316-
*num = bc_copy_num(BCG(_zero_));
317-
return false;
318316
}

0 commit comments

Comments
 (0)