Re: Question about Encoding a Custom Type - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: Question about Encoding a Custom Type
Date
Msg-id 9283E9BC-3561-428F-9F15-71461770D501@kineticode.com
Whole thread Raw
In response to Re: Question about Encoding a Custom Type  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Question about Encoding a Custom Type  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
On Jun 16, 2008, at 13:06, Tom Lane wrote:

> "David E. Wheeler" <david@kineticode.com> writes:
>> What's even weirder is that it can not work and then suddenly work:
>
> Smells like uninitialized-memory problems to me.  Perhaps you are
> miscalculating the length of the input data?

Entirely possible. Here are the two functions in which I calculate size:

char * cilower(text * arg) {    // Do I need to free anything here?    char * str = VARDATA_ANY( arg );
#ifdef USE_WIDE_UPPER_LOWER    // Have wstring_lower() do the work.    return wstring_lower( str );
# else    // Copy the string and process it.    int    inex, len;    char * result;
    index  = 0;    len    = VARSIZE(arg) - VARHDRSZ;    result = (char *) palloc( strlen( str ) + 1 );
    for (index = 0; index <= len; index++) {        result[index] = tolower((unsigned char) str[index] );    }
returnresult;
 
#endif   /* USE_WIDE_UPPER_LOWER */
}

int citextcmp (PG_FUNCTION_ARGS) {    // Could we do away with the varlena struct here?    text * left  =
PG_GETARG_TEXT_P(0);   text * right = PG_GETARG_TEXT_P(1);    char * lstr  = cilower( left );    char * rstr  =
cilower(right );    int    llen  = VARSIZE_ANY_EXHDR(left);    int    rlen  = VARSIZE_ANY_EXHDR(right);    return
varstr_cmp(lstr,llen, rstr, rlen);
 
}

> Are you testing in an --enable-cassert build?  The memory clobber
> stuff can help to make it more obvious where such problems lurk.

I've just recompiled with --enable-cassert and --enable-debug, but got  
no more information when I triggered the error, neither in psql nor in  
the log. :-(

Thanks,

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Question about Encoding a Custom Type
Next
From: Robert Treat
Date:
Subject: Re: How to Sponsor a Feature