This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #131627] extend stack in scalar-context pp_list when no args
authorAaron Crane <arc@cpan.org>
Sun, 16 Jul 2017 15:51:53 +0000 (16:51 +0100)
committerAaron Crane <arc@cpan.org>
Sun, 16 Jul 2017 15:51:53 +0000 (16:51 +0100)
In scalar (well, non-list) context, pp_list always yields exactly one stack
element. It must therefore extend the stack for that element, in case there
were no arguments on the stack when it started.

pp.c
t/op/list.t

diff --git a/pp.c b/pp.c
index 9ac4b07..efe629a 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -5185,6 +5185,7 @@ PP(pp_list)
     if (GIMME_V != G_ARRAY) {
        SV **mark = PL_stack_base + markidx;
        dSP;
+        EXTEND(SP, 1);          /* in case no arguments, as in @empty */
        if (++MARK <= SP)
            *MARK = *SP;                /* unwanted list, return last item */
        else
index 7bd3eb4..3f9487b 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     set_up_inc(qw(. ../lib));
 }
 
-plan( tests => 70 );
+plan( tests => 71 );
 
 @foo = (1, 2, 3, 4);
 cmp_ok($foo[0], '==', 1, 'first elem');
@@ -220,3 +220,11 @@ is(tied($t)->{fetched}, undef, 'assignment to empty list makes no copies');
 
 # this was passing a trash SV at the top of the stack to SvIV()
 ok(($0[()[()]],1), "[perl #126193] list slice with zero indexes");
+
+# RT #131732: pp_list must extend stack when empty-array arg and not in list
+# context
+{
+    my @x;
+    @x;
+    pass('no panic'); # panics only under DEBUGGING
+}