From: Gurusamy Sarathy Date: Tue, 13 Oct 1998 02:01:24 +0000 (+0000) Subject: force copy of substrings when matching against temporaries X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d080a6634fd73a615f3f2bc087428102f6a5c3e;p=p5sagit%2Fp5-mst-13.2.git force copy of substrings when matching against temporaries p4raw-id: //depot/perl@1942 --- diff --git a/pp_hot.c b/pp_hot.c index 75bdb4f..701f462 100644 --- 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; diff --git a/t/op/pat.t b/t/op/pat.t index f588734..8917e82 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -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++; +