On Tue, Sep 04, 2012 at 02:27:17AM +0200, Vincent Lefevre wrote: > The sprintf(3) man page says about sprintf(): > > sprintf(), snprintf(), vsprintf() and vsnprintf() write to the > character string str. > > but it does not say that a terminating null byte is written (this > is said only for snprintf() and vsnprintf() later). > [...] > The C99 standard is much more clear than the man page. It says: > > The sprintf function is equivalent to fprintf, except that the > output is written into an array (specified by the argument s) > rather than to a stream. A null character is written at the end > of the characters written; it is not counted as part of the > returned value. If copying takes place between objects that > overlap, the behavior is undefined. > > The man page could say: > > sprintf(), snprintf(), vsprintf() and vsnprintf() write a > sequence of characters to the array str; a null character > is written [or added] at the end of this sequence.
FWIW, the man page already states in RETURN VALUE | Upon successful return, these functions return the number of characters | printed (excluding the null byte used to end output to strings). providing some further hint at the terminating null byte. Still, in light of your counterexample (which I had omitted here) I feel this point might indeed need more stressing ... Cheers, Flo
signature.asc
Description: PGP signature