Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Dec 2011 19:31:02 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dimitry Andric <dim@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r228626 - head/usr.bin/csup
Message-ID:  <20111218191653.X1495@besplex.bde.org>
In-Reply-To: <201112171352.pBHDqr9l061685@svn.freebsd.org>
References:  <201112171352.pBHDqr9l061685@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 17 Dec 2011, Dimitry Andric wrote:

> Log:
>  In usr.bin/csup/proto.c, use the correct printf length modifier to print
>  an off_t.
> ...
> Modified: head/usr.bin/csup/proto.c
> ==============================================================================
> --- head/usr.bin/csup/proto.c	Sat Dec 17 13:14:44 2011	(r228625)
> +++ head/usr.bin/csup/proto.c	Sat Dec 17 13:52:53 2011	(r228626)
> ...
> @@ -751,7 +752,7 @@ proto_printf(struct stream *wr, const ch
> 			break;
> 		case 'O':
> 			off = va_arg(ap, off_t);
> -			rv = stream_printf(wr, "%llu", off);
> +			rv = stream_printf(wr, "%" PRId64, off);
> 			break;
> 		case 'S':
> 			s = va_arg(ap, char *);

PRId64 is another incorrect printf format.

off_t is typedefed so that it can be changed as neccessary.  Using
PRId64 hard-codes the assumption that it is precisely a 64 bit signed
integer.  It is indeed a signed integer (POSIX 2001 standard).  In
1990 POSIX, it was only required to be a signed arithmetic type, so
portable code had to handle the possibility that it was floating point,
and on systems with C90 compilers and 32-bit longs, it needed to be
floating point for it represent values a bit larger than 2**31-1.

In FreeBSD-1, it was 32 bits, so neither of the above would compile.
In FreeBSD[2-10], it is 64 bits integral.  FreeBSD depended on using
a non-C90 compiler even to declare it, and never needed floating point
for it, except for strict C90 support it would have needed a compat
layer with the int64_t kernel off_t trranslated to a long double
userland off_t.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111218191653.X1495>