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