From owner-cvs-all Mon Aug 20 7:13:28 2001 Delivered-To: cvs-all@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 0942337B408; Mon, 20 Aug 2001 07:13:17 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id AAA30118; Tue, 21 Aug 2001 00:13:14 +1000 Date: Tue, 21 Aug 2001 00:12:36 +1000 (EST) From: Bruce Evans X-X-Sender: To: Maxim Sobolev Cc: Brian Somers , , , Subject: Re: cvs commit: src/sbin/newfs mkfs.c src/sbin/ping6 ping6.c In-Reply-To: <200108201311.f7KDBvH15963@vega.vega.com> Message-ID: <20010820235013.E55658-100000@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 20 Aug 2001, Maxim Sobolev wrote: > > brian 2001/08/20 05:56:45 PDT > > > > Modified files: > > sbin/newfs mkfs.c > > sbin/ping6 ping6.c > > sbin/route route.c > > Log: > > Handle snprintf() returning -1. > > What is condition for snprintf() returning -1? The manpage doesn't provide > any clue, so as the SUSv2 specification. Perhaps manpage should be extended > to be more clear in this area. In C99: - if an encoding error occurred (then the return value may be any negative int, so checking for -1 is incorrect). In FreeBSD: - if the result is not representable as a (non-negative) int, then -1 is returned without changing errno. Example: format "foo%*s" with a preposterously larger field width. - I think encoding errors can't occur, because FreeBSD doesn't really support wide character stuff. In POSIX.1-200x: - as in C99, plus: - if the buffer size or the result is not representable as a (non-negative) int, then a negative value is returned and errno is set to EOVERFLOW. I think the buffer contents is indeterminate when snprintf() returns < 0, so the buffer might not be NUL-terminated. Some of Brian's changes didn't seem to handle this right. But the best way to handle snprintf() returning < 0 may be to crash. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message