Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Oct 2014 17:41:25 -0600
From:      Ian Lepore <ian@FreeBSD.org>
To:        Garrett Cooper <yaneurabeya@gmail.com>
Cc:        src-committers@freebsd.org, Bruce Evans <brde@optusnet.com.au>, svn-src-all@freebsd.org, svn-src-head@freebsd.org, Kurt Jaeger <pi@freebsd.org>, Konstantin Belousov <kostikbel@gmail.com>, Dag-Erling =?ISO-8859-1?Q?Sm=F8rgrav?= <des@des.no>
Subject:   Re: svn commit: r273734 - head/bin/dd
Message-ID:  <1414798885.17308.198.camel@revolution.hippie.lan>
In-Reply-To: <BACF8450-1ECB-4EBF-9EEB-C8D38F081BFC@gmail.com>
References:  <201410271138.s9RBcHrA002447@svn.freebsd.org> <20141027153957.GZ1877@kib.kiev.ua> <20141027155427.GM1492@f10.opsec.eu> <86vbn4egjt.fsf@nine.des.no> <20141028200418.E849@besplex.bde.org> <86mw8ged20.fsf@nine.des.no> <20141028210830.L1034@besplex.bde.org> <BACF8450-1ECB-4EBF-9EEB-C8D38F081BFC@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2014-10-31 at 14:30 -0700, Garrett Cooper wrote:
> On Oct 28, 2014, at 4:33, Bruce Evans <brde@optusnet.com.au> wrote:
>=20
> > On Tue, 28 Oct 2014, [utf-8] Dag-Erling Sm=B8rgrav wrote:
> >=20
> >> Bruce Evans <brde@optusnet.com.au> writes:
> >>> Dag-Erling Sm=B8rgrav <des@des.no> writes:
> >>>> This is a bug on all platforms, and both clang and (recent) gcc
> >>>> should complain about it.  That printf() call will print garbage.
> >>> No, this is only a bug on 32-bit arches.  The is is SSIZE_MAX.
> >>=20
> >> If you mean "it only has consequences on 32-bit arches", then I agre=
e -
> >> but it is still a bug to pass an int to %jd.
> >=20
> > This is machine-dependent.  intmax_t may be int.  The only requiremen=
t
> > on intmax_t is that it can represent any value of any signed integer
> > type.  This is possible if the largest integer type is 64 bits (the
> > smallest permitted largest type) and int is also 64 bits (and there
> > are no complications for padding bits).  intmax_t can even be signed
> > char if that is wide enough (not in POSIX starting 10-15 years ago,
> > since signed char is now required to be 8 bits.  It is weird for
> > intmax_t to have the lowest rank (not counting Bool), but FreeBSD use=
s
> > this loophole to make it have second highest rank on 64-bit arches.
>=20
> Indeed. For some giggles, look at this bug: https://bugs.freebsd.org/bu=
gzilla/show_bug.cgi?id=3D191674 ("printf("%tu", (intmax_t)-1) returns UIN=
T64_MAX on i386, not UINT32_MAX=A1).
> Cheers,

Isn't the problem in that bug that the cast doesn't match the printf
format, and the correct code would be something like the following?

 printf("%tu", (ptrdiff_t)-1);

-- Ian





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