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

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

Package: glibc-doc
Version: 2.1.1-5

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

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

I just spent over an hour trying to track down a bug in a program of
mine related to this....!



Reply to: