Re: bin/ln & WARNS=5

"M. Warner Losh" <[email protected]> Mon, 15 Jul 2002 09:04:20 -0600 (MDT)
Newsgroups gmane.os.freebsd.devel.audit
Message-ID <[email protected]>
In message: <[email protected]>
            Giorgos Keramidas <[email protected]> writes:
: +		if ((pathlen = snprintf(path, sizeof(path), "%s/%s",
: +		    source, p)) == -1 || pathlen >= (int)sizeof(path)) {

That's down right stupid.

snprintf never returns a negative number.  It always returns the
number of characters that it would have used to make the string.

The code was right before.  However, maybe the following is better and
clearer:

	if (strlen(source) + strlen(p) + 1 >= PATH_MAX) {
		... ETOOLONG stuff
	}	
	snprintf(...);

Warner

To Unsubscribe: send mail to [email protected]
with "unsubscribe freebsd-audit" in the body of the message