Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2014 20:28:16 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Kurt Jaeger <pi@freebsd.org>
Subject:   Re: svn commit: r273734 - head/bin/dd
Message-ID:  <20141028200418.E849@besplex.bde.org>
In-Reply-To: <86vbn4egjt.fsf@nine.des.no>
References:  <201410271138.s9RBcHrA002447@svn.freebsd.org> <20141027153957.GZ1877@kib.kiev.ua> <20141027155427.GM1492@f10.opsec.eu> <86vbn4egjt.fsf@nine.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 28 Oct 2014, [utf-8] Dag-Erling Sm=C3=B8rgrav wrote:

> Kurt Jaeger <pi@FreeBSD.org> writes:
>> Konstantin Belousov <kostikbel@gmail.com> writes:
>>> On Mon, Oct 27, 2014 at 11:38:17AM +0000, Kurt Jaeger wrote:
>>> /scratch/tmp/kib/src/bin/dd/args.c:192: warning: format '%jd' expects t=
ype 'intmax_t', but argument 3 has type 'int'
>> Thanks for the pointer. I'll take it up with the submitter.
>
> In an ideal world, you would have reviewed the patch before committing
> it...
>
>> I do not have a working arm setup right now.
>
> 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.  It has
type int on 32-bit arches and type long on 64-bit arches.  These types
are the same as ssize_t.  The compiler prints 'int' in the diagnostic
on 32-bit arches since it cannot see that the int is really an ssize_t.
SSIZE_MAX is defined as a literal constant with a correct type so that
it works in cpp expressions, so it doesn't have a cast to ssize_t.  At
least clang has more understanding of typedefed types then the C standard
requires, so it can distinguish identical types diagnostics.

Of course the patch is just broken in removing the casts of SSIZE_MAX.
They were carefully done to avoid precisely this portability bug.

Long long is an abomination, but you could find a lot of these portability
bugs on 64-bit arches by changing [u]intmax_t to [unsigned] <abomination>
while keeping [u]int64_t, [s]size_t and off_t as [unsigned] long.  Then
everything except [u]intmax_t and <abomination> would need to be cast to
print it using %j[du], the same as on 32-bit arches.  Only change this
transiently.  It breaks detection of the mismatch between <abomination>
and intmax_t.

Bruce
From owner-svn-src-head@FreeBSD.ORG  Tue Oct 28 09:52:40 2014
Return-Path: <owner-svn-src-head@FreeBSD.ORG>
Delivered-To: svn-src-head@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 8337F3C0;
 Tue, 28 Oct 2014 09:52:40 +0000 (UTC)
Received: from smtp.des.no (smtp.des.no [194.63.250.102])
 by mx1.freebsd.org (Postfix) with ESMTP id 2A772A;
 Tue, 28 Oct 2014 09:52:39 +0000 (UTC)
Received: from nine.des.no (smtp.des.no [194.63.250.102])
 by smtp-int.des.no (Postfix) with ESMTP id E51CEA9FC;
 Tue, 28 Oct 2014 09:52:38 +0000 (UTC)
Received: by nine.des.no (Postfix, from userid 1001)
 id 03CA0106AB; Tue, 28 Oct 2014 10:52:40 +0100 (CET)
From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To: Bruce Evans <brde@optusnet.com.au>
Subject: Re: svn commit: r273734 - head/bin/dd
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>
Date: Tue, 28 Oct 2014 10:52:39 +0100
In-Reply-To: <20141028200418.E849@besplex.bde.org> (Bruce Evans's message of
 "Tue, 28 Oct 2014 20:28:16 +1100 (EST)")
Message-ID: <86mw8ged20.fsf@nine.des.no>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Cc: Konstantin Belousov <kostikbel@gmail.com>, svn-src-head@freebsd.org,
 svn-src-all@freebsd.org, src-committers@freebsd.org,
 Kurt Jaeger <pi@freebsd.org>
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.18-1
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>;
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 28 Oct 2014 09:52:40 -0000

Bruce Evans <brde@optusnet.com.au> writes:
> Dag-Erling Sm=C3=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.

If you mean "it only has consequences on 32-bit arches", then I agree -
but it is still a bug to pass an int to %jd.

=C2=A77.19.6.1

 9 If a conversion specification is invalid, the behavior is
   undefined. 239) If any argument is not the correct type for the
   corresponding conversion specification, the behavior is undefined.

The term "correct type" is not defined anywhere, and is only used in the
descriptions of fprintf() and fwprintf().

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



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