Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix printf negative infinity #15965

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
Loading