@@ -1228,7 +1228,7 @@ Perl_my_atof(pTHX_ const char* s)
12281228
12291229#ifdef USE_QUADMATH
12301230
1231- Perl_my_atof2 ( aTHX_ s , & x );
1231+ my_atof2 ( s , & x );
12321232
12331233#elif ! defined(USE_LOCALE_NUMERIC )
12341234
@@ -1366,11 +1366,20 @@ S_my_atof_infnan(pTHX_ const char* s, bool negative, const char* send, NV* value
13661366
13671367char *
13681368Perl_my_atof2 (pTHX_ const char * orig , NV * value )
1369+ {
1370+ PERL_ARGS_ASSERT_MY_ATOF2 ;
1371+ return my_atof3 (orig , value , 0 );
1372+ }
1373+
1374+ char *
1375+ Perl_my_atof3 (pTHX_ const char * orig , NV * value , STRLEN len )
13691376{
13701377 const char * s = orig ;
13711378 NV result [3 ] = {0.0 , 0.0 , 0.0 };
13721379#if defined(USE_PERL_ATOF ) || defined(USE_QUADMATH )
1373- const char * send = s + strlen (orig ); /* one past the last */
1380+ const char * send = s + ((len != 0 )
1381+ ? len
1382+ : strlen (orig )); /* one past the last */
13741383 bool negative = 0 ;
13751384#endif
13761385#if defined(USE_PERL_ATOF ) && !defined(USE_QUADMATH )
@@ -1387,10 +1396,10 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
13871396#endif
13881397
13891398#if defined(USE_PERL_ATOF ) || defined(USE_QUADMATH )
1390- PERL_ARGS_ASSERT_MY_ATOF2 ;
1399+ PERL_ARGS_ASSERT_MY_ATOF3 ;
13911400
13921401 /* leading whitespace */
1393- while (isSPACE (* s ))
1402+ while (s < send && isSPACE (* s ))
13941403 ++ s ;
13951404
13961405 /* sign */
@@ -1408,6 +1417,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
14081417 char * endp ;
14091418 if ((endp = S_my_atof_infnan (aTHX_ s , negative , send , value )))
14101419 return endp ;
1420+ endp = send ;
14111421 result [2 ] = strtoflt128 (s , & endp );
14121422 if (s != endp ) {
14131423 * value = negative ? - result [2 ] : result [2 ];
@@ -1457,7 +1467,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
14571467 /* we accumulate digits into an integer; when this becomes too
14581468 * large, we add the total to NV and start again */
14591469
1460- while (1 ) {
1470+ while (s < send ) {
14611471 if (isDIGIT (* s )) {
14621472 seen_digit = 1 ;
14631473 old_digit = digit ;
@@ -1485,7 +1495,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
14851495 exp_adjust [0 ]++ ;
14861496 }
14871497 /* skip remaining digits */
1488- while (isDIGIT (* s )) {
1498+ while (s < send && isDIGIT (* s )) {
14891499 ++ s ;
14901500 if (! seen_dp ) {
14911501 exp_adjust [0 ]++ ;
@@ -1509,7 +1519,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
15091519 else if (!seen_dp && GROK_NUMERIC_RADIX (& s , send )) {
15101520 seen_dp = 1 ;
15111521 if (sig_digits > MAX_SIG_DIGITS ) {
1512- while (isDIGIT (* s )) {
1522+ while (s < send && isDIGIT (* s )) {
15131523 ++ s ;
15141524 }
15151525 break ;
@@ -1525,7 +1535,7 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
15251535 result [1 ] = S_mulexp10 (result [1 ], exp_acc [1 ]) + (NV )accumulator [1 ];
15261536 }
15271537
1528- if (seen_digit && (isALPHA_FOLD_EQ (* s , 'e' ))) {
1538+ if (s < send && seen_digit && (isALPHA_FOLD_EQ (* s , 'e' ))) {
15291539 bool expnegative = 0 ;
15301540
15311541 ++ s ;
@@ -1536,14 +1546,12 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value)
15361546 case '+' :
15371547 ++ s ;
15381548 }
1539- while (isDIGIT (* s ))
1549+ while (s < send && isDIGIT (* s ))
15401550 exponent = exponent * 10 + (* s ++ - '0' );
15411551 if (expnegative )
15421552 exponent = - exponent ;
15431553 }
15441554
1545-
1546-
15471555 /* now apply the exponent */
15481556
15491557 if (seen_dp ) {
0 commit comments