Skip to content

Commit 3b517e0

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-15964: printf() can strip sign of -INF
2 parents bc7902d + c2d3734 commit 3b517e0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ext/standard/formatted_print.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
246246
}
247247

248248
if (zend_isinf(number)) {
249-
is_negative = (number<0);
250-
php_sprintf_appendstring(buffer, pos, "INF", 3, 0, padding,
251-
alignment, 3, is_negative, 0, always_sign);
249+
is_negative = (number<0);
250+
char *str = is_negative ? "-INF" : "INF";
251+
php_sprintf_appendstring(buffer, pos, str, strlen(str), 0, padding,
252+
alignment, strlen(str), is_negative, 0, always_sign);
252253
return;
253254
}
254255

tests/strings/002.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ try {
4444
} catch(\ValueError $e) {
4545
print('Error found: '.$e->getMessage()."\n");
4646
}
47+
printf("printf test 31:%.17g\n", INF);
48+
printf("printf test 32:%.17g\n", -INF);
4749
vprintf("vprintf test 1:%2\$-2d %1\$2d\n", array(1, 2));
4850

4951

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

0 commit comments

Comments
 (0)