[perl #72090] unitialized variable name wrong with no strict refs
authorFather Chrysostomos <sprout@cpan.org>
Fri, 10 Dec 2010 22:54:13 +0000 (14:54 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 11 Dec 2010 00:09:32 +0000 (16:09 -0800)
$ ./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.

sv.c
t/lib/warnings/sv

diff --git a/sv.c b/sv.c
index c0c2458..2cabf7b 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -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;
            }
index dbab90b..e29553a 100644 (file)
@@ -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[]} ;