Re: bin/ln & WARNS=5

Mike Barcroft <[email protected]> Mon, 15 Jul 2002 12:19:58 -0400
Newsgroups gmane.os.freebsd.devel.audit
Organization The FreeBSD Project
Message-ID <[email protected]>
M. Warner Losh <[email protected]> writes:
> 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.

C99 standardized -1 as a possible return value for encoding errors.
I'm not sure why the return value is int and not ssize_t though
(probably because C99 doesn't have an ssize_t).

> The code was right before.  However, maybe the following is better and
> clearer:
> 
> 	if (strlen(source) + strlen(p) + 1 >= PATH_MAX) {
> 		... ETOOLONG stuff
> 	}	
> 	snprintf(...);

You might just as well use sprintf() at this point.

Best regards,
Mike Barcroft

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