Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ext/standard/formatted_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,16 @@ 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);
if (is_negative) {
// ideally negative should have been handled inside php_sprintf_appendstring ,
// but the code is difficult to debug, and it's easy to break stuff inside there (I tried, I broke stuff),
// handling it here is much easier..
php_sprintf_appendstring(buffer, pos, "-INF", 4, 0, padding,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coding the min_width argument (4) here, looks wrong to me (I am aware that this already had been done this way before); see https://3v4l.org/WtHcq. Why not simply pass width instead? Same for the NaN and the -INF cases.

alignment, 4, is_negative, 0, always_sign);
} else {
php_sprintf_appendstring(buffer, pos, "INF", 3, 0, padding,
alignment, 3, 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
Loading