Re: [perl #24346] pulling in stuff from outside the substr lvalue
authorGraham Barr <gbarr@pobox.com>
Wed, 29 Oct 2003 09:56:53 +0000 (09:56 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Sun, 29 Feb 2004 16:21:34 +0000 (16:21 +0000)
Message-Id: <3993BF6C-09F6-11D8-B6DD-0003938857CC@pobox.com>

make a variable aliased to an lvalue substr value work as expected

p4raw-id: //depot/perl@22414

mg.c

diff --git a/mg.c b/mg.c
index 340ab6a..51a12f1 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1780,16 +1780,21 @@ Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
        sv_utf8_upgrade(lsv);
        sv_pos_u2b(lsv, &lvoff, &lvlen);
        sv_insert(lsv, lvoff, lvlen, tmps, len);
+       LvTARGLEN(sv) = sv_len_utf8(sv);
        SvUTF8_on(lsv);
     }
     else if (lsv && SvUTF8(lsv)) {
        sv_pos_u2b(lsv, &lvoff, &lvlen);
+       LvTARGLEN(sv) = len;
        tmps = (char*)bytes_to_utf8((U8*)tmps, &len);
        sv_insert(lsv, lvoff, lvlen, tmps, len);
        Safefree(tmps);
     }
-    else
-        sv_insert(lsv, lvoff, lvlen, tmps, len);
+    else {
+       sv_insert(lsv, lvoff, lvlen, tmps, len);
+       LvTARGLEN(sv) = len;
+    }
+
 
     return 0;
 }