Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix phpGH-15964: printf() can strip sign of -INF
  • Loading branch information
cmb69 committed Dec 2, 2024
2 parents bc7902d + c2d3734 commit 3b517e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ext/standard/formatted_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
}

if (zend_isinf(number)) {
is_negative = (number<0);
php_sprintf_appendstring(buffer, pos, "INF", 3, 0, padding,
alignment, 3, is_negative, 0, always_sign);
is_negative = (number<0);
char *str = is_negative ? "-INF" : "INF";
php_sprintf_appendstring(buffer, pos, str, strlen(str), 0, padding,
alignment, strlen(str), is_negative, 0, always_sign);
return;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/strings/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ try {
} catch(\ValueError $e) {
print('Error found: '.$e->getMessage()."\n");
}
printf("printf test 31:%.17g\n", INF);
printf("printf test 32:%.17g\n", -INF);
vprintf("vprintf test 1:%2\$-2d %1\$2d\n", array(1, 2));


Expand Down Expand Up @@ -83,4 +85,6 @@ printf test 27:3 1 2
printf test 28:02 1
printf test 29:2 1
printf test 30:Error found: Argument number specifier must be greater than zero and less than 2147483647
printf test 31:INF
printf test 32:-INF
vprintf test 1:2 1

0 comments on commit 3b517e0

Please sign in to comment.