Re: Text search segmentation fault

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, Tommy Gildseth <tommy(dot)gildseth(at)usit(dot)uio(dot)no>, General Postgres Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Text search segmentation fault
Date: 2009-01-29 16:45:53
Message-ID: 877i4eoybi.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Gregory Stark <stark(at)enterprisedb(dot)com> writes:
>> Maybe I'm missing something but I don't understand how this fixes the problem.
>> s is a "char*" so type punning it to an unsigned char * before dereferencing
>> it is really the same as casting it to unsigned char directly
>
> No, it isn't. If char is signed then you'll get quite different results
> from a high-bit-set byte value, because sign extension will happen
> before the value is reinterpreted as unsigned.

What I wrote is correct. There's no sign extension if you're casting from
signed char to unsigned char since there's no extension.

I really think he should just change all the "unsigned int" into "unsigned
char" and not do the type punning with pointer casts. That's just evil.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's Slony Replication support!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-01-29 16:50:22 Re: Text search segmentation fault
Previous Message Bill Moran 2009-01-29 16:44:12 Re: Pet Peeves?