Skip to content

Commit 6ec69d7

Browse files
authoredMar 26, 2023
Improve the warning message for unpack() in case not enough values were provided (#10949)
1 parent 0b212ab commit 6ec69d7

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed
 

‎NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ PHP NEWS
151151
. password_hash() will now chain the original RandomException to the ValueError
152152
on salt generation failure. (timwolla)
153153
. Fix GH-10239 (proc_close after proc_get_status always returns -1). (nielsdos)
154+
. Improve the warning message for unpack() in case not enough values were
155+
provided. (nielsdos)
154156

155157
- Streams:
156158
. Fixed bug #51056: blocking fread() will block even if data is available.

‎ext/standard/pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ PHP_FUNCTION(unpack)
11781178
/* Reached end of input for '*' repeater */
11791179
break;
11801180
} else {
1181-
php_error_docref(NULL, E_WARNING, "Type %c: not enough input, need %d, have " ZEND_LONG_FMT, type, size, inputlen - inputpos);
1181+
php_error_docref(NULL, E_WARNING, "Type %c: not enough input values, need %d values but only " ZEND_LONG_FMT " %s provided", type, size, inputlen - inputpos, inputlen - inputpos == 1 ? "was" : "were");
11821182
zend_array_destroy(Z_ARR_P(return_value));
11831183
RETURN_FALSE;
11841184
}

‎ext/standard/tests/strings/bug61038.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ array(1) {
1717
string(5) "str%c%c"
1818
}
1919

20-
Warning: unpack(): Type a: not enough input, need 6, have 5 in %s on line %d
20+
Warning: unpack(): Type a: not enough input values, need 6 values but only 5 were provided in %s on line %d
2121
bool(false)
2222
array(1) {
2323
[1]=>

‎ext/standard/tests/strings/pack_Z.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var_dump(
1818
);
1919
?>
2020
--EXPECTF--
21-
Warning: unpack(): Type Z: not enough input, need 2, have 1 in %s on line %d
21+
Warning: unpack(): Type Z: not enough input values, need 2 values but only 1 was provided in %s on line %d
2222
string(0) ""
2323
string(5) "foo%c%c"
2424
string(4) "foo%c"

0 commit comments

Comments
 (0)