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