Skip to content

Commit

Permalink
[perl #106726] Don’t crash on length(@arr) warning
Browse files Browse the repository at this point in the history
The RT ticket blames this on 676a678, but it was actually commit
579333e.  676a678 extended this problem to evals (and modules),
but it already occurred in the main program.

This crashes:

    ./miniperl -Ilib -we 'sub {length my @forecasts}'

because it is trying to find the variable name for the warning in the
CV returned by find_runcv, but this is a *compile-time* warning, so
using find_runcv is just wrong.

It ends up looking for the array in PL_main_cv’s pad, instead of
PL_compcv.
  • Loading branch information
Father Chrysostomos committed Jan 18, 2012
1 parent e2054bc commit c6fb3f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion op.c
Original file line number Diff line number Diff line change
Expand Up @@ -9720,7 +9720,8 @@ Perl_ck_length(pTHX_ OP *o)
case OP_PADHV:
case OP_PADAV:
name = varname(
NULL, hash ? '%' : '@', kid->op_targ, NULL, 0, 1
(GV *)PL_compcv, hash ? '%' : '@', kid->op_targ,
NULL, 0, 1
);
break;
case OP_RV2HV:
Expand Down
6 changes: 4 additions & 2 deletions sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -13859,7 +13859,7 @@ Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ,
{

SV * const name = sv_newmortal();
if (gv) {
if (gv && isGV(gv)) {
char buffer[2];
buffer[0] = gvtype;
buffer[1] = 0;
Expand All @@ -13878,10 +13878,12 @@ Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ,
}
}
else {
CV * const cv = find_runcv(NULL);
CV * const cv = gv ? (CV *)gv : find_runcv(NULL);
SV *sv;
AV *av;

assert(!cv || SvTYPE(cv) == SVt_PVCV);

if (!cv || !CvPADLIST(cv))
return NULL;
av = MUTABLE_AV((*av_fetch(CvPADLIST(cv), 0, FALSE)));
Expand Down
9 changes: 8 additions & 1 deletion t/op/length.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
@INC = '../lib';
}

plan (tests => 37);
plan (tests => 38);

print "not " unless length("") == 0;
print "ok 1\n";
Expand Down Expand Up @@ -224,4 +224,11 @@ is($ul, undef, "Assigned length of overloaded undef with result in TARG");
print length undef;
}

{
local $SIG{__WARN__} = sub {
pass '[perl #106726] no crash with length @lexical warning'
};
eval ' sub { length my @forecasts } ';
}

is($warnings, 0, "There were no other warnings");

0 comments on commit c6fb3f6

Please sign in to comment.