Skip to content

Commit c2d3734

Browse files
divinity76cmb69
authored andcommitted
Fix phpGH-15964: printf() can strip sign of -INF
We need to cater to negative infinity explicitly. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes phpGH-15965.
1 parent 03bb112 commit c2d3734

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PHP NEWS
1515
skipLazyInitialization() may change initialized proxy). (Arnaud)
1616
. Fix is_zend_ptr() huge block comparison. (nielsdos)
1717
. Fixed potential OOB read in zend_dirname() on Windows. (cmb)
18+
. Fixed bug GH-15964 (printf() can strip sign of -INF). (divinity76, cmb)
1819

1920
- Curl:
2021
. Fix various memory leaks in curl mime handling. (nielsdos)

ext/standard/formatted_print.c

+4-3
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

+4
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)