From: Nick Ing-Simmons Date: Tue, 12 Dec 2000 14:48:27 +0000 (+0000) Subject: Re: Breadperl & Tk X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1aa79deb393ec5e9ddbda441a2842fd50725a7ba;p=p5sagit%2Fp5-mst-13.2.git Re: Breadperl & Tk Message-Id: <200012121448.OAA11516@mikado.tiuk.ti.com> p4raw-id: //depot/perl@8090 --- diff --git a/sv.c b/sv.c index c6b718c..5d388e0 100644 --- a/sv.c +++ b/sv.c @@ -2385,7 +2385,7 @@ void Perl_sv_utf8_upgrade(pTHX_ register SV *sv) { char *s, *t; - bool hibit; + int hibit = FALSE; if (!sv || !SvPOK(sv) || SvUTF8(sv)) return; @@ -2393,17 +2393,26 @@ Perl_sv_utf8_upgrade(pTHX_ register SV *sv) /* This function could be much more efficient if we had a FLAG in SVs * to signal if there are any hibit chars in the PV. */ - for (s = t = SvPVX(sv), hibit = FALSE; t < SvEND(sv) && !hibit; t++) - if (*t & 0x80) + for (s = t = SvPVX(sv); t < SvEND(sv) && !hibit; t++) { + if (*t & 0x80) { hibit = TRUE; + break; + } + } if (hibit) { - STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */ + STRLEN len; + if (SvREADONLY(sv) && SvFAKE(sv)) { + sv_force_normal(sv); + s = SvPVX(sv); + } + len = SvCUR(sv) + 1; /* Plus the \0 */ SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len); SvCUR(sv) = len - 1; + if (SvLEN(sv) != 0) + Safefree(s); /* No longer using what was there before. */ SvLEN(sv) = len; /* No longer know the real size. */ SvUTF8_on(sv); - Safefree(s); /* No longer using what was there before. */ } }