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

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware
Date: 2009-01-09 14:05:56
Message-ID: 496759C4.2040609@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Tom Lane wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>> Tom Lane wrote:
>>> 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?
>
> SUS phrases it as
>
> "If the total number of resulting wide-character codes including the
> terminating null wide-character code is no more than maxsize, wcsftime()
> returns the number of wide-character codes placed into the array pointed
> to by wcs, not including the terminating null wide-character
> code. Otherwise 0 is returned and the contents of the array are
> indeterminate."
>
> so it's very clear that maxsize is counted in wchars.
>
> Perhaps someone could experiment to double-check what Windows does.

Read up a bit more and compared, it definitely seems to mean the same
thing. My tests seem to agree as well.

I'll change it to MAX_L10N_DATA and strlcpy.

//Magnus

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Magnus Hagander 2009-01-09 14:07:00 pgsql: Code review of strftime patch, per comments from Tom: * Use
Previous Message Tom Lane 2009-01-09 13:55:51 Re: pgsql: Fix strftime usage on Win32 when trying to fetch the locale-aware