Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Nov 2011 09:35:51 +0100
From:      Stefan Farfeleder <stefanf@FreeBSD.org>
To:        Jilles Tjoelker <jilles@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r227369 - head/bin/sh
Message-ID:  <20111109083545.GC1598@mole.fafoe.narf.at>
In-Reply-To: <201111082354.pA8NsdhP055080@svn.freebsd.org>
References:  <201111082354.pA8NsdhP055080@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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?

Stefan



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