From owner-cvs-all Fri Jan 5 10:34: 2 2001 From owner-cvs-all@FreeBSD.ORG Fri Jan 5 10:33:56 2001 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from Awfulhak.org (awfulhak.demon.co.uk [194.222.196.252]) by hub.freebsd.org (Postfix) with ESMTP id D85EB37B400; Fri, 5 Jan 2001 10:33:54 -0800 (PST) Received: from hak.lan.Awfulhak.org (root@hak.lan.Awfulhak.org [172.16.0.12]) by Awfulhak.org (8.11.1/8.11.1) with ESMTP id f05IQSv01712; Fri, 5 Jan 2001 18:26:28 GMT (envelope-from brian@lan.Awfulhak.org) Received: from hak.lan.Awfulhak.org (brian@localhost [127.0.0.1]) by hak.lan.Awfulhak.org (8.11.1/8.11.1) with ESMTP id f05IWpi48258; Fri, 5 Jan 2001 18:32:51 GMT (envelope-from brian@hak.lan.Awfulhak.org) Message-Id: <200101051832.f05IWpi48258@hak.lan.Awfulhak.org> X-Mailer: exmh version 2.2 06/23/2000 with nmh-1.0.4 To: Matt Dillon Cc: Ben Smithurst , Brian Somers , Chris Faulhaber , Will Andrews , cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, brian@Awfulhak.org Subject: Re: cvs commit: src/usr.bin/apply apply.c In-Reply-To: Message from Matt Dillon of "Fri, 05 Jan 2001 09:33:47 PST." <200101051733.f05HXlY01207@earth.backplane.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 05 Jan 2001 18:32:51 +0000 From: Brian Somers Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > :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. That looks a lot better although personally I'd leave out the ``you did not supply a large enough buffer'' text. > -Matt -- Brian Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message