Re: Text search segmentation fault - Mailing list pgsql-general

From Gregory Stark
Subject Re: Text search segmentation fault
Date
Msg-id 87k58ep0uq.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: Text search segmentation fault  (Teodor Sigaev <teodor@sigaev.ru>)
Responses Re: Text search segmentation fault
Re: Text search segmentation fault
List pgsql-general
Teodor Sigaev <teodor@sigaev.ru> writes:

> I reproduced the bug with a help of Grzegorz's point for 64-bit box. So, patch
> is attached and I'm going to commit it
...

> !     Conf->flagval[(unsigned int) *s] = (unsigned char) val;
...
> !     Conf->flagval[*(unsigned char*) s] = (unsigned char) val;

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 and casting it
to unsigned int really ought to have done the same thing anyways.

All of the changes are of this type so I can't see how your patch could have
fixed the problem.

And in general casting the pointer before dereferencing it is a whole lot
scarier code which should raise eyebrows a lot faster than just a simple cast
to unsigned char like you had it originally.

What really boggles me is why you don't just use unsigned chars everywhere and
remove all of these casts. or would that just move the casts to strcmp and
company?

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

pgsql-general by date:

Previous
From: Richard Broersma
Date:
Subject: Re: Pet Peeves?
Next
From: Teodor Sigaev
Date:
Subject: Re: Text search segmentation fault