From: Jarkko Hietaniemi Date: Sat, 21 Oct 2000 00:44:18 +0000 (+0000) Subject: Fix for ID 20001020.006, concatenating an unset submatch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=689440ec6112b0ad8e13a518cfe8f7c6b95df346;p=p5sagit%2Fp5-mst-13.2.git Fix for ID 20001020.006, concatenating an unset submatch with utf8 resulted in "Modification of a read-only value". p4raw-id: //depot/perl@7383 --- diff --git a/pp_hot.c b/pp_hot.c index 9b0573b..d6a7f04 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -172,8 +172,14 @@ PP(pp_concat) /* Take a copy since we're about to overwrite TARG */ olds = s = (U8*)savepvn((char*)s, len); } - if (!SvOK(left) && SvTYPE(left) <= SVt_PVMG) - sv_setpv(left, ""); /* Suppress warning. */ + if (!SvOK(left) && SvTYPE(left) <= SVt_PVMG) { + if (SvREADONLY(left)) { + left = sv_2mortal(newSVpvn("", 0)); + left_utf = FALSE; + } + else + sv_setpv(left, ""); /* Suppress warning. */ + } l = (U8*)SvPV(left, targlen); left_utf |= DO_UTF8(left); if (TARG != left) diff --git a/t/pragma/utf8.t b/t/pragma/utf8.t index c3538c0..75f607d 100755 --- a/t/pragma/utf8.t +++ b/t/pragma/utf8.t @@ -10,7 +10,7 @@ BEGIN { } } -print "1..99\n"; +print "1..101\n"; my $test = 1; @@ -525,3 +525,22 @@ sub nok_bytes { $test++; } } + +{ + # ID 20001020.006 + + "x" =~ /(.)/; # unset $2 + + # Without the fix this will croak: + # Modification of a read-only value attempted at ... + "$2\x{1234}"; + + print "ok $test\n"; + $test++; + + # For symmetry with the above. + "\x{1234}$2"; + + print "ok $test\n"; + $test++; +}