From patchwork Tue Apr 8 07:04:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 27928 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0198420447 for ; Tue, 8 Apr 2014 07:16:48 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id hn18sf1979699igb.4 for ; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=WxR+ClQpbUjBto8Qw4y/y1DllYlTIczxiBFZdW1lgFQ=; b=Rf1bElZISc+tyLf5gs1uTdHKciaVoOsU8eszoxXjSOelQhW5EshAjgfi4zCWG/eeZX nzfvlOEhYLfCXjUVSqGOtq7u/golGZlA2f3Ngdpj9bQ9Efib6pQHXKu53Z6t2kQqm6Xu lDubZ/xA/fea+ZndM6Um0Np6zdakiYceN/5BC5rndYn5n8mnVYhACrjRrJLU6Lq/ybOm UuIllZCNzb//eKmi4kfi4WIbOk3okerb3NSG1KOLnxyBzQptuJGNMAqTyOpfzP6tGtSc 7bjUytlArl1tYmsO7koLkyXeMZd4KfqzMPjbk/PuKg+k7ot/EGE9p4ocLAAYvuJV0CuH owPA== X-Gm-Message-State: ALoCoQlCpWdreXsK25sZbQRzF5n8gEOWxHHHGXhbs0m4LW0F6eDJpbXHNat/gIwzdv3Y0mKs6mtM X-Received: by 10.43.92.73 with SMTP id bp9mr979671icc.26.1396941408484; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.241 with SMTP id 104ls113996qgf.24.gmail; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) X-Received: by 10.58.122.164 with SMTP id lt4mr1793585veb.2.1396941408370; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id w5si243020vcl.66.2014.04.08.00.16.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 00:16:48 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id oz11so409506veb.19 for ; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) X-Received: by 10.220.170.202 with SMTP id e10mr1799561vcz.20.1396941408293; Tue, 08 Apr 2014 00:16:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp222904vcv; Tue, 8 Apr 2014 00:16:48 -0700 (PDT) X-Received: by 10.224.26.71 with SMTP id d7mr2157757qac.29.1396941407864; Tue, 08 Apr 2014 00:16:47 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m6si474386qcg.34.2014.04.08.00.16.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 00:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:38496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQH1-0004Yy-30 for patch@linaro.org; Tue, 08 Apr 2014 03:16:47 -0400 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 Received: from isrv.corpit.ru ([86.62.121.231]:56750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQEW-0004Mg-OV; Tue, 08 Apr 2014 03:14:12 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 14BD340E37; Tue, 8 Apr 2014 11:14:12 +0400 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id 461AB6AD; Tue, 8 Apr 2014 11:04:13 +0400 (MSK) Received: (nullmailer pid 10577 invoked by uid 1000); Tue, 08 Apr 2014 07:04:12 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Tue, 8 Apr 2014 11:04:06 +0400 Message-Id: <1396940651-10513-7-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 Cc: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Subject: [Qemu-devel] [PULL 06/11] int128.h: Avoid undefined behaviours involving signed arithmetic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mjt@tls.msk.ru X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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)