DragonFly BSD
DragonFly submit List (threaded) for 2005-01
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: A few WARNS6 cleanups


From: Chris Pressey <cpressey@xxxxxxxxxxxxxxx>
Date: Mon, 3 Jan 2005 14:20:29 -0800

On Mon, 3 Jan 2005 11:40:00 -0800
Chris Pressey <cpressey@xxxxxxxxxxxxxxx> wrote:

> Or to take another example, this one from SUSv3:
> 
> "SYNOPSIS
> 
> 	#include <stdio.h>
> 	...
> 	int snprintf(char *restrict s, size_t n,
>  	      const char *restrict format, ...);
> 	...
> 
> RETURN VALUE
> 
> 	...
> 	Upon successful completion, the snprintf() function shall return
> 	the number of bytes that would be written to s had n been
> 	sufficiently large excluding the terminating null byte."

My mistake: snprintf can return -1, according to POSIX, but our manual
page is sufficiently confusing about it that I read it as meaning that
it cannot.  I'll try to fix our manual page.

> In other words, snprintf can never return a negative number.  Yet its
> return value is signed.  This means that the fairly common idiom
> 
> 	if (snprintf(buf, sizeof(f), f, ...) > sizeof(f)) { err(); }

This also means this idiom is an incomplete check, and I'll fix them as
I come to them.

-Chris



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]