Date: Tue, 21 Aug 2001 00:12:36 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Maxim Sobolev <sobomax@FreeBSD.org> Cc: Brian Somers <brian@FreeBSD.org>, <kris@FreeBSD.org>, <cvs-committers@FreeBSD.org>, <cvs-all@FreeBSD.org> Subject: Re: cvs commit: src/sbin/newfs mkfs.c src/sbin/ping6 ping6.c Message-ID: <20010820235013.E55658-100000@besplex.bde.org> In-Reply-To: <200108201311.f7KDBvH15963@vega.vega.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010820235013.E55658-100000>