Skip to content

Improve the warning message for unpack() in case not enough values were provided #10949

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

Merged
merged 1 commit into from
Mar 26, 2023
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ PHP NEWS
. password_hash() will now chain the original RandomException to the ValueError
on salt generation failure. (timwolla)
. Fix GH-10239 (proc_close after proc_get_status always returns -1). (nielsdos)
. Improve the warning message for unpack() in case not enough values were
provided. (nielsdos)

- Streams:
. Fixed bug #51056: blocking fread() will block even if data is available.
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ PHP_FUNCTION(unpack)
/* Reached end of input for '*' repeater */
break;
} else {
php_error_docref(NULL, E_WARNING, "Type %c: not enough input, need %d, have " ZEND_LONG_FMT, type, size, inputlen - inputpos);
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");
zend_array_destroy(Z_ARR_P(return_value));
RETURN_FALSE;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/strings/bug61038.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ array(1) {
string(5) "str%c%c"
}

Warning: unpack(): Type a: not enough input, need 6, have 5 in %s on line %d
Warning: unpack(): Type a: not enough input values, need 6 values but only 5 were provided in %s on line %d
bool(false)
array(1) {
[1]=>
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/strings/pack_Z.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var_dump(
);
?>
--EXPECTF--
Warning: unpack(): Type Z: not enough input, need 2, have 1 in %s on line %d
Warning: unpack(): Type Z: not enough input values, need 2 values but only 1 was provided in %s on line %d
string(0) ""
string(5) "foo%c%c"
string(4) "foo%c"
Expand Down