develooper Front page | perl.perl5.porters | Postings from December 2000

Re: UTF8 flag and sv_utf8_upgrade

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
December 12, 2000 05:52
Subject:
Re: UTF8 flag and sv_utf8_upgrade
Message ID:
200012121352.NAA11374@mikado.tiuk.ti.com
Nick Ing-Simmons <nik@tiuk.ti.com> writes:
>Nick Ing-Simmons <nik@tiuk.ti.com> writes:
>>B. When I fix A in Tk sources it core dumps in a manner which suggests
>>   something has done heap-overrun.
>
>Debugging this I discovered a "feature" of sv_utf8_upgrade:

What a synchronicity of issues !

I posted this:

>
>void
>Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
>{
>    char *s, *t;
>    bool hibit;
>
>    if (!sv || !SvPOK(sv) || SvUTF8(sv))
>	return;
>
>    /* 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)
>	    hibit = TRUE;
>
>    if (hibit) {
>	STRLEN len = SvCUR(sv) + 1; /* Plus the \0 */
>	SvPVX(sv) = (char*)bytes_to_utf8((U8*)s, &len);
>	SvCUR(sv) = len - 1;
>	SvLEN(sv) = len; /* No longer know the real size. */
>	SvUTF8_on(sv);
>	Safefree(s); /* No longer using what was there before. */
>    }
>}

and 

Nicholas Clark <nick@ccl4.org> writes:
>How come sv_2iv has
>	if (SvREADONLY(sv) && SvFAKE(sv)) {
>	    sv_force_normal(sv);
>	}
>
>but sv_2uv and sv_2nv don't have the same code in the similar position?

And the Tk bug is related to both!

For reasons that are not clear to me SPARC/gcc-2.95.2 is mis-compiling
that code:

hibit=262144 s=283410 t=283411 e=283416 
SV = PVIV(0x393468) at 0x397e34
  REFCNT = 1
  FLAGS = (TEMP,POK,FAKE,READONLY,pPOK)
  IV = 1941317403
  PV = 0x283410 "-class"
  CUR = 6
  LEN = 0

Thus I am getting false +ve 'highbit' on the '-' character.
This in turn leads to the string being upgraded and then Safefree'ing 
something which it shouldn't - hence SEGV later.

-- 
Nick Ing-Simmons <nik@tiuk.ti.com>
Via, but not speaking for: Texas Instruments Ltd.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About