Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Jan 2001 09:33:47 -0800 (PST)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        Ben Smithurst <ben@FreeBSD.ORG>
Cc:        Brian Somers <brian@Awfulhak.org>, Chris Faulhaber <jedgar@fxp.org>, Will Andrews <will@FreeBSD.ORG>, cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG
Subject:   Re: cvs commit: src/usr.bin/apply apply.c
Message-ID:  <200101051733.f05HXlY01207@earth.backplane.com>
References:  <jedgar@fxp.org> <200101050206.f0526rB87964@hak.lan.Awfulhak.org> <20010105162917.K85794@strontium.scientia.demon.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help

:Brian Somers wrote:
:
:> Also (and this bug was already there), s[n]printf() returns the length 
:> of what it would have liked to have put in the target, not what it 
:> actually wrote.  If the first s[n]printf() above ends up truncating, 
:> the second one will happily overflow.
:
:Well, with sprintf, there is no difference, since it doesn't have a size
:limitation like snprintf does.
:
:> s[n]printf() is poorly documented in this area.
:
:Would this change make you feel better?
:
:change this:
:
:     Snprintf() and vsnprintf() will write at most size-1 of the characters
:     printed into the output string (the size'th character then gets the ter-
:     minating `\0'); if the return value is greater than or equal to the size
:     argument, the string was too short and some of the printed characters
:     were discarded.
:
:to this:
:
:     Snprintf() and vsnprintf() will write at most size-1 of the characters
:     printed into the output string (the size'th character then gets the ter-
:     minating `\0'), and return the number of characters written to the
:     buffer, excluding the terminating `\0'.  This value may be less than the
:     number of characters which would have been written, had the buffer been
:     large enough; if the return value is greater than or equal to the size
:     argument, the string was too short and some of the printed characters
:     were discarded.
:
:-- 
:Ben Smithurst / ben@FreeBSD.org / PGP: 0x99392F7D

    That's worse.  Try this:

    snprintf() and vsnprintf() will write at most size-1 characters to the
    output buffer (the size'th character then gets the terminating `\0').
    These functions return the number of characters (excluding the terminator)
    that would have been written had the buffer been large enough.  If the
    return value is greater than or equal to the size argument, you did not
    supply a large enough buffer and the output will be truncated.

						-Matt


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200101051733.f05HXlY01207>