Fix for ID 20001020.006, concatenating an unset submatch
Jarkko Hietaniemi [Sat, 21 Oct 2000 00:44:18 +0000 (00:44 +0000)]
with utf8 resulted in "Modification of a read-only value".

p4raw-id: //depot/perl@7383

pp_hot.c
t/pragma/utf8.t

index 9b0573b..d6a7f04 100644 (file)
--- 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)
index c3538c0..75f607d 100755 (executable)
@@ -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++;
+}