summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>2012-05-23 14:50:31 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-05-23 17:59:22 -0700
commit21361d0729743e699b2954b542f05a2e4eabd980 (patch)
treeb4f46494969725415a45b9c85172af1ba8cf0d24
parent909564a7d63dd41ca03b7bc9659d8c7b695220d2 (diff)
downloadperl-21361d0729743e699b2954b542f05a2e4eabd980.tar.gz
[perl #60204] Unhelpful error message from unpack
Nigel Sandever said: > The error message produced by the following snippets is very unhelpful: > > c:\>perl -wle"print unpack 'v/a*', qq[a]" > '/' must follow a numeric type in unpack at -e line 1. > > c:\>perl -wle"print unpack 'v/a*', ''" > '/' must follow a numeric type in unpack at -e line 1. > > c:\>perl -wle"print unpack 'v/a*', ' '" > '/' must follow a numeric type in unpack at -e line 1. The "problem" is that the data string is too short. But unpack doesn't generate a warning (or croak) in this case for simple patterns: mhx@r2d2 $ perl -MData::Dumper -we'print Dumper([unpack "n", "a"])' $VAR1 = []; So, I'd say your code should just behave in exactly the same way. No warning, no return values.
-rw-r--r--pp_pack.c2
-rw-r--r--t/op/pack.t12
2 files changed, 11 insertions, 3 deletions
diff --git a/pp_pack.c b/pp_pack.c
index 71dc22d67d..9f1c83a34b 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -2234,7 +2234,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
if (symptr->flags & FLAG_SLASH){
if (SP - PL_stack_base - start_sp_offset <= 0)
- Perl_croak(aTHX_ "'/' must follow a numeric type in unpack");
+ break;
if( next_symbol(symptr) ){
if( symptr->howlen == e_number )
Perl_croak(aTHX_ "Count after length/code in unpack" );
diff --git a/t/op/pack.t b/t/op/pack.t
index 43189ab538..34097adaa6 100644
--- a/t/op/pack.t
+++ b/t/op/pack.t
@@ -12,7 +12,7 @@ my $no_endianness = $] > 5.009 ? '' :
my $no_signedness = $] > 5.009 ? '' :
"Signed/unsigned pack modifiers not available on this perl";
-plan tests => 14700;
+plan tests => 14704;
use strict;
use warnings qw(FATAL all);
@@ -816,13 +816,21 @@ SKIP: {
{
# /
- my ($x, $y, $z);
+ my ($x, $y, $z, @a);
eval { ($x) = unpack '/a*','hello' };
like($@, qr!'/' must follow a numeric type!);
undef $x;
eval { $x = unpack '/a*','hello' };
like($@, qr!'/' must follow a numeric type!);
+ # [perl #60204] Unhelpful error message from unpack
+ eval { @a = unpack 'v/a*','h' };
+ is($@, '');
+ is(scalar @a, 0);
+ eval { $x = unpack 'v/a*','h' };
+ is($@, '');
+ is($x, undef);
+
undef $x;
eval { ($z,$x,$y) = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" };
is($@, '');