From 876f9b78003ed912f0fabb8426118678775ffcf5 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Tue, 8 Nov 2011 23:54:39 +0000 Subject: [PATCH] sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic. With i386 base gcc and i386 base clang, arith_yacc.o remains unchanged. --- bin/sh/arith_yacc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c index 041e638211ef..48c63eac789c 100644 --- a/bin/sh/arith_yacc.c +++ b/bin/sh/arith_yacc.c @@ -131,11 +131,11 @@ static arith_t do_binop(int op, arith_t a, arith_t b) 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: