This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [perl #27803] perl crashes when utf8::upgrade($offsetOK_scalar)
authorSADAHIRO Tomoyuki <BQW10602@nifty.com>
Sun, 21 Mar 2004 15:19:22 +0000 (00:19 +0900)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 21 Mar 2004 13:18:01 +0000 (13:18 +0000)
Message-Id: <20040321151828.DAC6.BQW10602@nifty.com>

p4raw-id: //depot/perl@22545

lib/utf8.t
sv.c

index 90035e5..334a476 100644 (file)
@@ -37,7 +37,7 @@ no utf8; # Ironic, no?
 #
 #
 
-plan tests => 144;
+plan tests => 145;
 
 {
     # bug id 20001009.001
@@ -415,3 +415,13 @@ SKIP: {
     like($@, qr/^Modification of a read-only value attempted/,
         "utf8::encode should refuse to touch read-only values");
 }
+
+{
+    my $a =3D "456\xb6";
+    utf8::upgrade($a);
+
+    my $b =3D "123456\xb6";
+    $b =3D~ s/^...//;
+    utf8::upgrade($b);
+    is($b, $a, "utf8::upgrade OffsetOK");
+}
diff --git a/sv.c b/sv.c
index f4b3696..02e2b55 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3494,7 +3494,8 @@ Perl_sv_utf8_upgrade_flags(pTHX_ register SV *sv, I32 flags)
         }
         if (hibit) {
              STRLEN len;
-       
+             SvOOK_off(sv);
+             s = (U8*)SvPVX(sv);
              len = SvCUR(sv) + 1; /* Plus the \0 */
              SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len);
              SvCUR(sv) = len - 1;