From: SADAHIRO Tomoyuki Date: Sun, 21 Mar 2004 15:19:22 +0000 (+0900) Subject: Re: [perl #27803] perl crashes when utf8::upgrade($offsetOK_scalar) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=06a4563224066c07e70fee61255fea3909c889cc;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #27803] perl crashes when utf8::upgrade($offsetOK_scalar) Message-Id: <20040321151828.DAC6.BQW10602@nifty.com> p4raw-id: //depot/perl@22545 --- diff --git a/lib/utf8.t b/lib/utf8.t index 90035e5..334a476 100644 --- a/lib/utf8.t +++ b/lib/utf8.t @@ -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 --- 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;