Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware - Mailing list pgsql-committers

From Magnus Hagander
Subject Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware
Date
Msg-id 49675685.1020103@hagander.net
Whole thread Raw
In response to Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-committers
Tom Lane wrote:
> mha@postgresql.org (Magnus Hagander) writes:
>> Fix strftime usage on Win32 when trying to fetch the locale-aware
>> parts of a time string so it properly handles different encodings.
>
> Hmm, this patch has
>
> +     wchar_t    wbuf[MAX_L10N_DATA];
> +
> +     len = wcsftime(wbuf, sizeof(wbuf), format, tm);
>
> The Single Unix Spec's definition of wcsftime says that the above
> risks a buffer overrun, and the correct second argument would be
> MAX_L10N_DATA.  Now I realize that SUS is a poor guide for
> Windows-specific code, but are you sure this is right?

Now that I read it again, I think you're right. What MS says is:
"If the total number of characters, including the terminating null, is
more than maxsize, both strftime and wcsftime return 0 and the contents
of strDest are indeterminate."

The important difference being "character" vs "bytes", right?


> Also, I believe we've deprecated StrNCpy; use strlcpy if possible.

Ok, I'll change that.

//Magnus

pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware