From owner-svn-src-head@FreeBSD.ORG Wed Nov 9 20:35:32 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BBEFA106566B; Wed, 9 Nov 2011 20:35:32 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 1F9308FC0A; Wed, 9 Nov 2011 20:35:32 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 4495F1DD415; Wed, 9 Nov 2011 21:35:29 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 2AE9E28468; Wed, 9 Nov 2011 21:35:29 +0100 (CET) Date: Wed, 9 Nov 2011 21:35:29 +0100 From: Jilles Tjoelker To: Stefan Farfeleder Message-ID: <20111109203528.GA29992@stack.nl> References: <201111082354.pA8NsdhP055080@svn.freebsd.org> <20111109083545.GC1598@mole.fafoe.narf.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20111109083545.GC1598@mole.fafoe.narf.at> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r227369 - head/bin/sh X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 20:35:32 -0000 On Wed, Nov 09, 2011 at 09:35:51AM +0100, Stefan Farfeleder wrote: > On Tue, Nov 08, 2011 at 11:54:39PM +0000, Jilles Tjoelker wrote: > > Author: jilles > > Date: Tue Nov 8 23:54:39 2011 > > New Revision: 227369 > > URL: http://svn.freebsd.org/changeset/base/227369 > > Log: > > sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic. > > With i386 base gcc and i386 base clang, arith_yacc.o remains unchanged. > > Modified: > > head/bin/sh/arith_yacc.c > > Modified: head/bin/sh/arith_yacc.c > > ============================================================================== > > --- head/bin/sh/arith_yacc.c Tue Nov 8 23:44:26 2011 (r227368) > > +++ head/bin/sh/arith_yacc.c Tue Nov 8 23:54:39 2011 (r227369) > > @@ -131,11 +131,11 @@ static arith_t do_binop(int op, arith_t > > yyerror("divide error"); > > return op == ARITH_REM ? a % b : a / b; > > case ARITH_MUL: > > - return a * b; > > + return (uintmax_t)a * (uintmax_t)b; > > case ARITH_ADD: > > - return a + b; > > + return (uintmax_t)a + (uintmax_t)b; > > case ARITH_SUB: > > - return a - b; > > + return (uintmax_t)a - (uintmax_t)b; > > case ARITH_LSHIFT: > > return a << b; > > case ARITH_RSHIFT: > Isn't the behaviour undefined too when you convert an out-of-range > uintmax_t value back into an intmax_t value? The result is implementation-defined or an implementation-defined signal is raised. GCC documentation (gcc.info 4.5 Integers implementation) says this ] * `The result of, or the signal raised by, converting an integer to a ] signed integer type when the value cannot be represented in an ] object of that type (C90 6.2.1.2, C99 6.3.1.3).' ] For conversion to a type of width N, the value is reduced modulo ] 2^N to be within range of the type; no signal is raised. which is exactly what we need. -- Jilles Tjoelker