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

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



>>>>> Ben Pfaff writes:

Ben> Package: glibc-doc
Ben> Version: 2.1.1-5

Ben> The glibc 2.1 documentation says that snprintf returns the number of
Ben> characters that would have been written to the buffer, regardless of
Ben> whether the buffer was actually big enough to hold that number of
Ben> characters.

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.

Andreas
-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de


Reply to: