<feed xmlns='http://www.w3.org/2005/Atom'>
<title>src/lib/libc/stdio/vsnprintf.c, branch stable/4</title>
<subtitle>FreeBSD source tree</subtitle>
<id>https://cgit-dev.freebsd.org/src/atom?h=stable%2F4</id>
<link rel='self' href='https://cgit-dev.freebsd.org/src/atom?h=stable%2F4'/>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/'/>
<updated>2003-08-27T18:20:57Z</updated>
<entry>
<title>MFC revision 1.22: When size is 1 should just null terminate the string.</title>
<updated>2003-08-27T18:20:57Z</updated>
<author>
<name>Kelly Yancey</name>
<email>kbyanc@FreeBSD.org</email>
</author>
<published>2003-08-27T18:20:57Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=de58aa68b0f730dba431bbab8f7aad866fba6612'/>
<id>urn:sha1:de58aa68b0f730dba431bbab8f7aad866fba6612</id>
<content type='text'>
This fix has the side effect of making vsnprintf() properly return the
length of the string that would have been created if the buffer were
infinite length when the passed size is 1.  Previously, it would
erroniously return 0 which causes auto-extending sbufs to misbehave in
userland apps linked against libsbuf.

Approved by:	re (jhb)
</content>
</entry>
<entry>
<title>MFC rev. 1.21: fix vsnprintf(3) memory leak for size == 0.</title>
<updated>2002-09-23T06:58:17Z</updated>
<author>
<name>Maxim Konovalov</name>
<email>maxim@FreeBSD.org</email>
</author>
<published>2002-09-23T06:58:17Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=77a5659f0752189c3e2f23e2799f144776709497'/>
<id>urn:sha1:77a5659f0752189c3e2f23e2799f144776709497</id>
<content type='text'>
Approved by:	re (jhb)
</content>
</entry>
<entry>
<title>$Id$ -&gt; $FreeBSD$</title>
<updated>1999-08-28T00:22:10Z</updated>
<author>
<name>Peter Wemm</name>
<email>peter@FreeBSD.org</email>
</author>
<published>1999-08-28T00:22:10Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=7f3dea244c40159a41ab22da77a434d7c5b5e85a'/>
<id>urn:sha1:7f3dea244c40159a41ab22da77a434d7c5b5e85a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>1. EOF was returned when the buffer size was larger than INT_MAX.  This</title>
<updated>1998-01-01T20:15:58Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1998-01-01T20:15:58Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=8c6d2f42e1780917ba89400da7b7c084e56d7c49'/>
<id>urn:sha1:8c6d2f42e1780917ba89400da7b7c084e56d7c49</id>
<content type='text'>
   case has very little to do with the output size being larger than
   INT_MAX.
2. The new #include of &lt;limits.h&gt; was disordered.
3. The new declaration of `on' was disordered (integer types go together).
4. Testing an unsigned value for &gt; 0 was fishy.

Submitted by: bde
</content>
</entry>
<entry>
<title>Correct type of stored argument place (from previous fix)</title>
<updated>1997-12-24T23:54:19Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1997-12-24T23:54:19Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=fb25537fb854c86555f13528b8775406942328b6'/>
<id>urn:sha1:fb25537fb854c86555f13528b8775406942328b6</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Return back to BSD snprintf semantics which recent C9x standard adopts</title>
<updated>1997-12-24T23:02:47Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1997-12-24T23:02:47Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=6e690ad4ca3f240aa8deb1a18660c97c72e6d2c3'/>
<id>urn:sha1:6e690ad4ca3f240aa8deb1a18660c97c72e6d2c3</id>
<content type='text'>
instead of Singe Unix, thanx Bruce for explaining, I am not realize
standards war was there.

But now, fix n == 0 case to not return error and fix check for too
big n.

Things left to do: check for overflow in arguments.
</content>
</entry>
<entry>
<title>1) Oops! Insert again if (n == 0) return 0.</title>
<updated>1997-12-24T20:24:08Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1997-12-24T20:24:08Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=e0b123f6d0eca4574a0d93f3e4f1f0d2aa93b4c4'/>
<id>urn:sha1:e0b123f6d0eca4574a0d93f3e4f1f0d2aa93b4c4</id>
<content type='text'>
Final word is Bruce's quote:

C9x specifies the BSD4.4-Lite behaviour:

       [#3] ...   Thus,  the
       null-terminated  output  has  been completely written if and
       only if the returned value is less than n.

It means that if we not have any null-terminated output as for n == 0
we can't return value less than n, so we forced to return value
equal to n i.e. 0

The next good thing is glibc compatibility, of course.

2) Do check for too big n in machine-independent way.
3) Minor optimization assuming EOF is &lt; 0
</content>
</entry>
<entry>
<title>Back out part related to "return 0 if n == 0" and return EOF as before.</title>
<updated>1997-12-24T14:32:40Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1997-12-24T14:32:40Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=5ebfa8de69f7860ed332336eff6bc7978a05852d'/>
<id>urn:sha1:5ebfa8de69f7860ed332336eff6bc7978a05852d</id>
<content type='text'>
The main argument is that it is impossible to determine if %n evaluated or not
when snprintf return 0, because it can happens for both n == 0 and n == 1.
Although EOF here is good indication of the end of process, if n is
decreased in the loop...
Since it is already supposed in many places that EOF *is* negative, f.e.
from Single Unix specs for snprintf
"return ... a negative value if an output error was encountered"
this not makes situation worse.
</content>
</entry>
<entry>
<title>snprintf return value fixes to conform Single Unix specs:</title>
<updated>1997-12-24T12:31:32Z</updated>
<author>
<name>Andrey A. Chernov</name>
<email>ache@FreeBSD.org</email>
</author>
<published>1997-12-24T12:31:32Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=4ecaf22055282efee8a087248dea361f7246c109'/>
<id>urn:sha1:4ecaf22055282efee8a087248dea361f7246c109</id>
<content type='text'>
1) if buffer size is smaller than arguments size, return buffer
size, not arguments size as before.

2) if buffer size is 0, return 0, not EOF as before.
(now it is compatible with Linux and Apache implementations too).

NOTE: Single Unix specs says:

If the value of n {buffer size} is zero on a call to snprintf(), an
unspecified value less than 1 is returned.

It means we can't return EOF since EOF can take *any* value in general
not especially &lt; 1. Better variant will be return -1 (it is less then
1 and different with n == 1 case) but -1 value is already occuped by
EOF in our implementation, so we can't distinguish true IO error
in that case. So 0 here is only possible case still conforming
to Single Unix specs.
</content>
</entry>
<entry>
<title>Revert $FreeBSD$ to $Id$</title>
<updated>1997-02-22T15:12:41Z</updated>
<author>
<name>Peter Wemm</name>
<email>peter@FreeBSD.org</email>
</author>
<published>1997-02-22T15:12:41Z</published>
<link rel='alternate' type='text/html' href='https://cgit-dev.freebsd.org/src/commit/?id=7e546392b5fe3a496acff53ac7aadd1c57b2a4cf'/>
<id>urn:sha1:7e546392b5fe3a496acff53ac7aadd1c57b2a4cf</id>
<content type='text'>
</content>
</entry>
</feed>
