[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 4.0 core dump from printf -v foo %s b
From: |
Chet Ramey |
Subject: |
Re: 4.0 core dump from printf -v foo %s b |
Date: |
Thu, 12 Nov 2009 14:37:58 -0500 |
User-agent: |
Thunderbird 2.0.0.23 (Macintosh/20090812) |
Andreas Schwab wrote:
> Greg Wooledge <wooledg@eeg.ccf.org> writes:
>
>> It doesn't mention a null pointer. The OpenBSD man page does explicitly
>> say the null pointer is allowed if size is zero. The GNU/Linux man page
>> says that SUSv2 and C99 disagree, but that the implementation follows
>> C99 (allowing the null pointer when size is 0).
>
> Note that there are more differences between SUSv2 and POSIX.1-2008/C99:
> The SUSv2 version of snprintf returns the actual number of bytes written
> (excluding the terminating NUL if any), whereas the C99 version returns
> the number of bytes that would have been written (excluding the
> terminating NUL) if the buffer would be big enough.
That is true. There is a note in the Posix.1-2008/SUSv3 description that
explicitly states that the functionality is supposed to align with the C
standard and defers to C99 in case of conflict.
I try to write to the current (well, ten-year-old) standards. The
replacement in lib/sh/snprintf.c behaves as C99 specifies; you might try
using it by #undefing HAVE_VSNPRINTF and HAVE_SNPRINTF in config.h.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/