[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] Re: nit in strftime.c

From: Eric Blake
Subject: [bug-gnulib] Re: nit in strftime.c
Date: Tue, 15 Mar 2005 18:25:09 -0700
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Hash: SHA1

According to Jim Meyering on 3/15/2005 4:15 PM:
>>Why not prime the buffer?  Pass in an additional character in ufmt on the 
>>side (such as " %p" instead of "%p"), then ignore it on return, to distinguish
>>between failure (return == 0) and success (return > 0, length of interest is
>>return - 1).  Then you are not relying on (theoretical) non-portable behavior,
>>and can distinguish between %p that expands to nothing vs. %p that overflows
>>sizeof ubuf.

> How about this patch?
> 2005-03-15  Jim Meyering  <address@hidden>
>       * strftime.c (my_strftime): Prepend a byte to the format string
>       that's passed to the underlying strftime, solely to ensure that
>       a return value of zero now reliably indicates failure.
>         This also reverts yesterday's change.
>       Suggestion from Eric Blake.

Looks fine to me.

> -         char ufmt[4];
> +         char ufmt[5];
>           char *u = ufmt;
>           char ubuf[1024]; /* enough for any single format in practice */

You didn't increase sizeof ubuf, but is a 1024-byte expansion for %p any
more likely than 1023 bytes?

Also, remember that my_strftime(NULL, ...) is documented to return the
size that would be expanded.  Is it worth adding a configure check as to
whether the underlying strftime also has that property, and in that case
calling it twice to malloc an array that is guaranteed to be large enough,
enough even if some weird locale does have a 1025-byte %p?  This is
probably too theoretical to be worth bothering with, but I thought I'd
mention it.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
Version: GnuPG v1.4.0 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]