Received: from eggs.gnu.org ([2001:4830:134:3::10]:48584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQEc-0001hH-7D for qemu-devel@nongnu.org; Tue, 08 Apr 2014 03:14:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXQEX-0004NA-0V for qemu-devel@nongnu.org; Tue, 08 Apr 2014 03:14:18 -0400 From: Michael Tokarev Date: Tue, 8 Apr 2014 11:04:06 +0400 Message-Id: <1396940651-10513-7-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1396940651-10513-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1396940651-10513-1-git-send-email-mjt@msgid.tls.msk.ru> Subject: [Qemu-devel] [PULL 06/11] int128.h: Avoid undefined behaviours involving signed arithmetic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev From: Peter Maydell Add casts when we're performing arithmetic on the .hi parts of an Int128, to avoid undefined behaviour. Signed-off-by: Peter Maydell Signed-off-by: Michael Tokarev --- include/qemu/int128.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/int128.h b/include/qemu/int128.h index 9ed47aa..f597031 100644 --- a/include/qemu/int128.h +++ b/include/qemu/int128.h @@ -53,7 +53,7 @@ static inline Int128 int128_rshift(Int128 a, int n) if (n >= 64) { return (Int128) { h, h >> 63 }; } else { - return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), h }; + return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h }; } } @@ -78,7 +78,7 @@ static inline Int128 int128_neg(Int128 a) static inline Int128 int128_sub(Int128 a, Int128 b) { - return (Int128){ a.lo - b.lo, a.hi - b.hi - (a.lo < b.lo) }; + return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) }; } static inline bool int128_nonneg(Int128 a) -- 1.7.10.4