Skip to content
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

Inconsistent/missing warnings with pack #17314

Open
Tux opened this issue Nov 19, 2019 · 0 comments
Open

Inconsistent/missing warnings with pack #17314

Tux opened this issue Nov 19, 2019 · 0 comments

Comments

@Tux
Copy link
Contributor

Tux commented Nov 19, 2019

All tested with perl-5.30.0

  1. pack does not warn when not enough arguments are passed:
$ perl -wE'use strict; $a = pack "s>s>s> s>", 1, 2, 3'
  1. pack does warn when passing explicit undef:
$ perl -wE'use strict; $a = pack "s>s>s> s>", 1, 2, 3, undef'
Use of uninitialized value in pack at -e line 1.

So, what is the difference? Why does the first not warn?

Likewise
3. pack does not warn when not enough arguments in array:

$ perl -wE'use strict; my @v = (1..3); $a = pack "s>s>s> s>", @v'
  1. pack does not warn when too many arguments in array:
$ perl -wE'use strict; my @v = (1..5); $a = pack "s>s>s> s>", @v'
  1. pack does warn when array has explicit undef:
$ perl -wE'use strict; my @v = (1..3,undef); $a = pack "s>s>s> s>", @v'
Use of uninitialized value $v[3] in pack at -e line 1.

It took my hours to find why

 my @v = unpack "..... s>s>s>" => $input;

had three trailing zeroes where the value was generated in another process passing it through a pipe

 $input = pack "..... s>s>s>", @values;

and @values was missing the three last values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant