force copy of substrings when matching against temporaries
authorGurusamy Sarathy <gsar@cpan.org>
Tue, 13 Oct 1998 02:01:24 +0000 (02:01 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Tue, 13 Oct 1998 02:01:24 +0000 (02:01 +0000)
p4raw-id: //depot/perl@1942

pp_hot.c
t/op/pat.t

index 75bdb4f..701f462 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -863,9 +863,9 @@ PP(pp_match)
            }
        }
     }
-    safebase = (((gimme == G_ARRAY) || global || !rx->nparens)
-               && !PL_sawampersand);
-    safebase = safebase ? 0  : REXEC_COPY_STR ;
+    safebase = ((gimme != G_ARRAY && !global && rx->nparens)
+               || SvTEMP(TARG) || PL_sawampersand)
+               ? REXEC_COPY_STR : 0;
     if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
        SAVEINT(PL_multiline);
        PL_multiline = pm->op_pmflags & PMf_MULTILINE;
@@ -1626,7 +1626,8 @@ PP(pp_subst)
                  && SvTYPE(rx->check_substr) == SVt_PVBM
                  && SvVALID(rx->check_substr)) 
                ? TARG : Nullsv);
-    safebase = (!rx->nparens && !PL_sawampersand) ? 0 : REXEC_COPY_STR;
+    safebase = (rx->nparens || SvTEMP(TARG) || PL_sawampersand)
+               ? REXEC_COPY_STR : 0;
     if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
        SAVEINT(PL_multiline);
        PL_multiline = pm->op_pmflags & PMf_MULTILINE;
index f588734..8917e82 100755 (executable)
@@ -692,3 +692,8 @@ print "not "
 print "ok $test\n";
 $test++;
 
+# see if matching against temporaries (created via pp_helem()) is safe
+{ foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
+print "$1\n";
+$test++;
+