Skip to content

Commit c6ffb1b

Browse files
committed
Fix GH-18897: printf: empty precision is interpreted as precision 6, not as precision 0
Like in other languages, and especially C where printf originates from, a missing precision should be treated as a 0 precision. Because the ADJ_PRECISION flag was not set, the double formatting code resetted the precision to the default float precision of 6.
1 parent 4f1b005 commit c6ffb1b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ext/standard/formatted_print.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
587587
expprec = 1;
588588
} else {
589589
precision = 0;
590+
adjusting |= ADJ_PRECISION;
590591
}
591592
} else {
592593
precision = 0;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
GH-18897 (printf: empty precision is interpreted as precision 6, not as precision 0)
3+
--FILE--
4+
<?php
5+
printf("%.f\n", 3.1415926535);
6+
printf("%.0f\n", 3.1415926535);
7+
?>
8+
--EXPECT--
9+
3
10+
3

0 commit comments

Comments
 (0)