[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 00:59:14 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Paul Eggert <eggert <at> CS.UCLA.EDU> writes:
> Unfortunately we cannot rely only on POSIX guarantees here, because
> POSIX says that the contents of the output buffer are unspecified if
> the output buffer is too small. A failing POSIX strftime can set the
> first byte of the output buffer to NUL.
>
> That being said, I like that patch since it's more likely that
> strftime won't arbitrarily set ubuf[0]=='\0'. To save you the time I
> installed the patch into gnulib and coreutils.
>
Why not prime the buffer? Pass in an additional character in ufmt on the front
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.
--
Eric Blake