Merge branch 'PHP-8.1'

* PHP-8.1:
  Fix bug #69751
This commit is contained in:
Nikita Popov 2021-09-29 12:21:56 +02:00
commit 23e6856e41
4 changed files with 35 additions and 7 deletions

View file

@ -385,7 +385,7 @@ int php_sprintf_get_argnum(char **format, size_t *format_len) {
int argnum = php_sprintf_getnumber(format, format_len); int argnum = php_sprintf_getnumber(format, format_len);
if (argnum <= 0) { 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; return ARG_NUM_INVALID;
} }

View 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

View file

@ -35,4 +35,4 @@ unlink( $file );
--EXPECT-- --EXPECT--
-- Testing vfprintf() function with other strangeties -- -- Testing vfprintf() function with other strangeties --
vfprintf(): Argument #1 ($stream) must be of type resource, string given 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.

View file

@ -18,9 +18,9 @@ printf("printf test 7:%010.2f\n", 2.5);
printf("printf test 8:<%20s>\n", "foo"); printf("printf test 8:<%20s>\n", "foo");
printf("printf test 9:<%-20s>\n", "bar"); printf("printf test 9:<%-20s>\n", "bar");
printf("printf test 10: 123456789012345\n"); 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: 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 12:%5.2f\n", -12.34);
printf("printf test 13:%5d\n", -12); printf("printf test 13:%5d\n", -12);
printf("printf test 14:%c\n", 64); printf("printf test 14:%c\n", 64);
@ -61,9 +61,9 @@ printf test 7:0000002.50
printf test 8:< foo> printf test 8:< foo>
printf test 9:<bar > printf test 9:<bar >
printf test 10: 123456789012345 printf test 10: 123456789012345
printf test 10:<høyesterettsjustitiarius> printf test 10:<hoyesterettsjustitiarius>
printf test 11: 123456789012345678901234567890 printf test 11: 123456789012345678901234567890
printf test 11:< høyesterettsjustitiarius> printf test 11:< hoyesterettsjustitiarius>
printf test 12:-12.34 printf test 12:-12.34
printf test 13: -12 printf test 13: -12
printf test 14:@ printf test 14:@
@ -82,5 +82,5 @@ printf test 26:2 1
printf test 27:3 1 2 printf test 27:3 1 2
printf test 28:02 1 printf test 28:02 1
printf test 29:2 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 vprintf test 1:2 1