Navigation Menu

Skip to content

Commit

Permalink
[perl #72090] unitialized variable name wrong with no strict refs
Browse files Browse the repository at this point in the history
$ ./perl -we '$a = @$a > 0'
Use of uninitialized value $a in array dereference at -e line 1.
Use of uninitialized value $a in numeric gt (>) at -e line 1.

S_find_uninit_var was not taking into account that rv2*v could return
undef. So it merrily looked at the child ops to find one that named
a variable.

This commit makes it skip any rv2av/rv2hv that does not have an OP_GV
as its child op.

In other words, it skips @{...} and %{...} (including the shorthand
forms @$foo and %$foo), but not @foo or %foo.
  • Loading branch information
Father Chrysostomos committed Dec 11, 2010
1 parent 98be99d commit 6d1f089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sv.c
Expand Up @@ -14031,6 +14031,12 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
if ( (type == OP_CONST && SvOK(cSVOPx_sv(kid)))
|| (type == OP_NULL && ! (kid->op_flags & OPf_KIDS))
|| (type == OP_PUSHMARK)
|| (
/* @$a and %$a, but not @a or %a */
(type == OP_RV2AV || type == OP_RV2HV)
&& cUNOPx(kid)->op_first
&& cUNOPx(kid)->op_first->op_type != OP_GV
)
)
continue;
}
Expand Down
7 changes: 7 additions & 0 deletions t/lib/warnings/sv
Expand Up @@ -209,6 +209,13 @@ Use of uninitialized value $a in join or string at - line 4.
Use of uninitialized value $a in concatenation (.) or string at - line 5.
Use of uninitialized value $a in concatenation (.) or string at - line 6.
########
# [perl #72090]
use warnings 'uninitialized';
$a = @$a > 0;
EXPECT
Use of uninitialized value $a in array dereference at - line 3.
Use of uninitialized value in numeric gt (>) at - line 3.
########
# sv.c
use warnings 'numeric' ;
sub TIESCALAR{bless[]} ;
Expand Down

0 comments on commit 6d1f089

Please sign in to comment.