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

Bug#38392: glibc-doc: documentation of snprintf return value is deceptive



Andreas Jaeger <aj@arthur.rhein-neckar.de> writes:

   Ben> It does not mention that in glibc 2.0 (and earlier?), if the buffer
   Ben> wasn't large enough to hold the format output, it would return -1
   Ben> instead of the number of characters that would have been written.
   Ben> This is deceptive, because it leads the reader to believe that he can
   Ben> depend on the return value for the size of a buffer to allocate, which
   Ben> is not true if you want to be glibc 2.0 or earlier compatible.

   This changed between glibc 2.0 and 2.1 because ISO C 9x requires this:

   1997-03-08 05:30  Ulrich Drepper  <drepper@cygnus.com>

	   * libio/vsnprintf.c: Change implementation to follow ISO C 9X
	   proposal.  The return value now is always the number of characters
	   which would be written if enough space is available.
	   * manual/stdio.texi: Update description for new behaviour.

It's still a bug in the documentation, even if it's not a bug in the
code.  It should mention that older versions of glibc behave
differently.  There's no excuse for gratuitously causing bugs because
people believe the documentation and try to use functions in
accordance with it.
-- 
Regarding a Microsoft/Xerox agreement:
	"This is a match made in heaven. 
	 Both companies excel at copying other people's work."
--douglas@min.net <URL:http://slashdot.org/article.pl?sid=99/05/16/2211252>


Reply to: