Skip to content

Commit d94e901

Browse files
committed
Fix uninitialized error in my_atof3()
This function, newly introduced in 5.29, by 6928bed, is buggy due to my misreading the man page for strtoflt128(). There was no man page on my system, and the one on-line is very terse, and could be interpreted as doing what I wanted, which is to have the second parameter on input point to the end position in the input string beyond which the function is not to look. But in fact the function is expecting a NUL-terminated string. This commit creates such a string by copying the original when it isn't NUL-terminated, before calling strtoflt128().
1 parent 76416d1 commit d94e901

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

numeric.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,30 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, STRLEN len)
14391439
#ifdef USE_QUADMATH
14401440
{
14411441
char* endp;
1442+
char* copy = NULL;
1443+
14421444
if ((endp = S_my_atof_infnan(aTHX_ s, negative, send, value)))
14431445
return endp;
1444-
endp = send;
1446+
1447+
/* If the length is passed in, the input string isn't NUL-terminated,
1448+
* and in it turns out the function below assumes it is; therefore we
1449+
* create a copy and NUL-terminate that */
1450+
if (len) {
1451+
Newx(copy, len + 1, char);
1452+
Copy(orig, copy, len, char);
1453+
copy[len] = '\0';
1454+
s = copy + (s - orig);
1455+
}
1456+
14451457
result[2] = strtoflt128(s, &endp);
1458+
1459+
/* If we created a copy, 'endp' is in terms of that. Convert back to
1460+
* the original */
1461+
if (copy) {
1462+
endp = (endp - copy) + (char *) orig;
1463+
Safefree(copy);
1464+
}
1465+
14461466
if (s != endp) {
14471467
*value = negative ? -result[2] : result[2];
14481468
return endp;

0 commit comments

Comments
 (0)