From: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Question about Encoding a Custom Type |
Date: | 2008-06-16 18:29:33 |
Message-ID: | 9283E9BC-3561-428F-9F15-71461770D501@kineticode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Jun 16, 2008, at 13:06, Tom Lane wrote:
> "David E. Wheeler" <david(at)kineticode(dot)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] );
}
return result;
#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
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2008-06-16 18:41:23 | Re: How to Sponsor a Feature |
Previous Message | Tom Lane | 2008-06-16 18:06:52 | Re: Question about Encoding a Custom Type |