mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Fix bug #69751
Change error message of sprintf/printf for missing/invalid position specifier to make it clear that this is talking about the specifier, not the number of arguments passed to the function. Also mention the upper limit of INT_MAX. Closes GH-7515.
This commit is contained in:
parent
6f6fd27d2f
commit
41df5c0675
5 changed files with 39 additions and 7 deletions
4
NEWS
4
NEWS
|
@ -32,6 +32,10 @@ PHP NEWS
|
|||
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
|
||||
(cmb, Nikita, Tyson Andre)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug #69751 (Change Error message of sprintf/printf for missing/typo
|
||||
position specifier). (Aliaksandr Bystry)
|
||||
|
||||
- XML:
|
||||
. Fixed bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace).
|
||||
(Aliaksandr Bystry, cmb)
|
||||
|
|
|
@ -385,7 +385,7 @@ int php_sprintf_get_argnum(char **format, size_t *format_len) {
|
|||
|
||||
int argnum = php_sprintf_getnumber(format, format_len);
|
||||
if (argnum <= 0) {
|
||||
zend_value_error("Argument number must be greater than zero");
|
||||
zend_value_error("Argument number specifier must be greater than zero and less than %d", INT_MAX);
|
||||
return ARG_NUM_INVALID;
|
||||
}
|
||||
|
||||
|
|
28
ext/standard/tests/strings/bug69751.phpt
Normal file
28
ext/standard/tests/strings/bug69751.phpt
Normal file
|
@ -0,0 +1,28 @@
|
|||
--TEST--
|
||||
Bug #69751: Change Error message of sprintf/printf for missing/typo position specifier.
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
sprintf('%$s, %2$s %1$s', "a", "b");
|
||||
} catch (ValueError $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
sprintf('%3$s, %2$s %1$s', "a", "b");
|
||||
} catch (ArgumentCountError $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
try {
|
||||
sprintf('%2147483648$s, %2$s %1$s', "a", "b");
|
||||
} catch (ValueError $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Argument number specifier must be greater than zero and less than %d
|
||||
4 arguments are required, 3 given
|
||||
Argument number specifier must be greater than zero and less than %d
|
|
@ -35,4 +35,4 @@ unlink( $file );
|
|||
--EXPECT--
|
||||
-- Testing vfprintf() function with other strangeties --
|
||||
vfprintf(): Argument #1 ($stream) must be of type resource, string given
|
||||
Error found: Argument number must be greater than zero.
|
||||
Error found: Argument number specifier must be greater than zero and less than 2147483647.
|
||||
|
|
|
@ -18,9 +18,9 @@ printf("printf test 7:%010.2f\n", 2.5);
|
|||
printf("printf test 8:<%20s>\n", "foo");
|
||||
printf("printf test 9:<%-20s>\n", "bar");
|
||||
printf("printf test 10: 123456789012345\n");
|
||||
printf("printf test 10:<%15s>\n", "høyesterettsjustitiarius");
|
||||
printf("printf test 10:<%15s>\n", "hoyesterettsjustitiarius");
|
||||
printf("printf test 11: 123456789012345678901234567890\n");
|
||||
printf("printf test 11:<%30s>\n", "høyesterettsjustitiarius");
|
||||
printf("printf test 11:<%30s>\n", "hoyesterettsjustitiarius");
|
||||
printf("printf test 12:%5.2f\n", -12.34);
|
||||
printf("printf test 13:%5d\n", -12);
|
||||
printf("printf test 14:%c\n", 64);
|
||||
|
@ -61,9 +61,9 @@ printf test 7:0000002.50
|
|||
printf test 8:< foo>
|
||||
printf test 9:<bar >
|
||||
printf test 10: 123456789012345
|
||||
printf test 10:<høyesterettsjustitiarius>
|
||||
printf test 10:<hoyesterettsjustitiarius>
|
||||
printf test 11: 123456789012345678901234567890
|
||||
printf test 11:< høyesterettsjustitiarius>
|
||||
printf test 11:< hoyesterettsjustitiarius>
|
||||
printf test 12:-12.34
|
||||
printf test 13: -12
|
||||
printf test 14:@
|
||||
|
@ -82,5 +82,5 @@ printf test 26:2 1
|
|||
printf test 27:3 1 2
|
||||
printf test 28:02 1
|
||||
printf test 29:2 1
|
||||
printf test 30:Error found: Argument number must be greater than zero
|
||||
printf test 30:Error found: Argument number specifier must be greater than zero and less than 2147483647
|
||||
vprintf test 1:2 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue