Re: B-Tree support function number 3 (strxfrm() optimization)
От | Heikki Linnakangas |
---|---|
Тема | Re: B-Tree support function number 3 (strxfrm() optimization) |
Дата | |
Msg-id | 533984E9.8040808@vmware.com обсуждение исходный текст |
Ответ на | Re: B-Tree support function number 3 (strxfrm() optimization) (Peter Geoghegan <pg@heroku.com>) |
Ответы |
Re: B-Tree support function number 3 (strxfrm() optimization)
|
Список | pgsql-hackers |
On 03/31/2014 08:51 AM, Peter Geoghegan wrote: > + #ifdef HAVE_LOCALE_T > + if (tss->locale) > + strxfrm_l(pres, tss->buf1, Min(sizeof(Datum), len), tss->locale); > + else > + #endif > + strxfrm(pres, tss->buf1, Min(sizeof(Datum), len)); > + > + pres[Min(sizeof(Datum) - 1, len)] = '\0'; I'm afraid that trick isn't 100% reliable. The man page for strxrfm says: > RETURN VALUE > The strxfrm() function returns the number of bytes required to store > the transformed string in dest excluding the terminating null byte > ('\0'). If the value returned is n or more, the contents of dest are > indeterminate. Note the last sentence. To avoid the undefined behavior, you have to pass a buffer that's large enough to hold the whole result, and then truncate the result. - Heikki
В списке pgsql-hackers по дате отправления: