Skip to content

Commit 3dfdf96

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix bug #69751
2 parents 2b25ac6 + 41df5c0 commit 3dfdf96

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

ext/standard/formatted_print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ int php_sprintf_get_argnum(char **format, size_t *format_len) {
385385

386386
int argnum = php_sprintf_getnumber(format, format_len);
387387
if (argnum <= 0) {
388-
zend_value_error("Argument number must be greater than zero");
388+
zend_value_error("Argument number specifier must be greater than zero and less than %d", INT_MAX);
389389
return ARG_NUM_INVALID;
390390
}
391391

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #69751: Change Error message of sprintf/printf for missing/typo position specifier.
3+
--FILE--
4+
<?php
5+
6+
try {
7+
sprintf('%$s, %2$s %1$s', "a", "b");
8+
} catch (ValueError $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
try {
13+
sprintf('%3$s, %2$s %1$s', "a", "b");
14+
} catch (ArgumentCountError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
sprintf('%2147483648$s, %2$s %1$s', "a", "b");
20+
} catch (ValueError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
?>
25+
--EXPECTF--
26+
Argument number specifier must be greater than zero and less than %d
27+
4 arguments are required, 3 given
28+
Argument number specifier must be greater than zero and less than %d

ext/standard/tests/strings/vfprintf_error4.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ unlink( $file );
3535
--EXPECT--
3636
-- Testing vfprintf() function with other strangeties --
3737
vfprintf(): Argument #1 ($stream) must be of type resource, string given
38-
Error found: Argument number must be greater than zero.
38+
Error found: Argument number specifier must be greater than zero and less than 2147483647.

tests/strings/002.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ printf("printf test 7:%010.2f\n", 2.5);
1818
printf("printf test 8:<%20s>\n", "foo");
1919
printf("printf test 9:<%-20s>\n", "bar");
2020
printf("printf test 10: 123456789012345\n");
21-
printf("printf test 10:<%15s>\n", "høyesterettsjustitiarius");
21+
printf("printf test 10:<%15s>\n", "hoyesterettsjustitiarius");
2222
printf("printf test 11: 123456789012345678901234567890\n");
23-
printf("printf test 11:<%30s>\n", "høyesterettsjustitiarius");
23+
printf("printf test 11:<%30s>\n", "hoyesterettsjustitiarius");
2424
printf("printf test 12:%5.2f\n", -12.34);
2525
printf("printf test 13:%5d\n", -12);
2626
printf("printf test 14:%c\n", 64);
@@ -61,9 +61,9 @@ printf test 7:0000002.50
6161
printf test 8:< foo>
6262
printf test 9:<bar >
6363
printf test 10: 123456789012345
64-
printf test 10:<høyesterettsjustitiarius>
64+
printf test 10:<hoyesterettsjustitiarius>
6565
printf test 11: 123456789012345678901234567890
66-
printf test 11:< høyesterettsjustitiarius>
66+
printf test 11:< hoyesterettsjustitiarius>
6767
printf test 12:-12.34
6868
printf test 13: -12
6969
printf test 14:@
@@ -82,5 +82,5 @@ printf test 26:2 1
8282
printf test 27:3 1 2
8383
printf test 28:02 1
8484
printf test 29:2 1
85-
printf test 30:Error found: Argument number must be greater than zero
85+
printf test 30:Error found: Argument number specifier must be greater than zero and less than 2147483647
8686
vprintf test 1:2 1

0 commit comments

Comments
 (0)