Re: Text search segmentation fault

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: 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:06:49
Message-ID: 87fxj2p04m.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gregory Stark <stark(at)enterprisedb(dot)com> writes:

> Teodor Sigaev <teodor(at)sigaev(dot)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.

Ah, I understand how this fixes the problem. You were casting to unsigned
*int* not unsigned char so it was sign extending first and then overflowing.
So char<255> was coming out as MAX_INT instead of 255.

#include <stdio.h>

main()
{
volatile signed char a = -1;
printf("ud=%ud\n", (unsigned int)a);
}

$ ./a.out
ud=4294967295d

If you just make these all casts to (unsigned char) it should work just as
well as the pointer type punning -- and be a whole lot less scary.

> 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?

It still seems to me if you put a few "unsigned" in variable declarations you
could remove piles upon piles of casts and make all of the code more readable.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Chiaramello 2009-01-29 16:14:02 Re: chinese parser for text search !
Previous Message Teodor Sigaev 2009-01-29 16:04:59 Re: Text search segmentation fault