Don’t push nulls on to the stack in pp_padav
authorFather Chrysostomos <sprout@cpan.org>
Sun, 25 Aug 2013 18:19:44 +0000 (11:19 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 25 Aug 2013 19:12:36 +0000 (12:12 -0700)
This is something that ce0d59fdd1c missed.

This will probably fix most of the modules mentioned in
ticket #119433.

pp.c
t/op/array.t

diff --git a/pp.c b/pp.c
index 56d63f3..46294b3 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -98,7 +98,11 @@ PP(pp_padav)
            }
        }
        else {
-           Copy(AvARRAY((const AV *)TARG), SP+1, maxarg, SV*);
+           PADOFFSET i;
+           for (i=0; i < (PADOFFSET)maxarg; i++) {
+               SV * const sv = AvARRAY((const AV *)TARG)[i];
+               SP[i+1] = sv ? sv : &PL_sv_undef;
+           }
        }
        SP += maxarg;
     }
index 4c3be2c..604553f 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require 'test.pl';
 }
 
-plan (136);
+plan (137);
 
 #
 # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
@@ -472,6 +472,10 @@ sub {
       'exists returns true for &PL_sv_undef elem [perl #7508]';
     is \$_[0], \undef, 'undef preserves identity in array [perl #109726]';
 }->(undef);
+# and that padav also knows how to handle the resulting NULLs
+@_ = sub { my @a; $a[1]=1; @a }->();
+is join (" ", map $_//"undef", @_), "undef 1",
+  'returning my @a with nonexistent elements'; 
 
 # [perl #118691]
 @plink=@plunk=();