This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #78194] Make list slices copy PADTMPs in lv cx
[perl5.git] / pp.c
diff --git a/pp.c b/pp.c
index cadfe96..99f7d1f 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4773,6 +4773,7 @@ PP(pp_lslice)
     SV ** const firstlelem = PL_stack_base + POPMARK + 1;
     SV ** const firstrelem = lastlelem + 1;
     I32 is_something_there = FALSE;
+    const U8 mod = PL_op->op_flags & OPf_MOD;
 
     const I32 max = lastrelem - lastlelem;
     SV **lelem;
@@ -4804,6 +4805,8 @@ PP(pp_lslice)
            is_something_there = TRUE;
            if (!(*lelem = firstrelem[ix]))
                *lelem = &PL_sv_undef;
+           else if (mod && SvPADTMP(*lelem) && !IS_PADGV(*lelem))
+               *lelem = firstrelem[ix] = sv_mortalcopy(*lelem);
        }
     }
     if (is_something_there)