From patchwork Fri Mar 28 15:12:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27305 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 399FF20545 for ; Fri, 28 Mar 2014 15:13:03 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 200sf6819374ykr.2 for ; Fri, 28 Mar 2014 08:13:03 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MW7xAhBGWJLY+FLneH59tZOoL9f04eXLTPpUN4dAxU4=; b=bwzL4SaaYsrCPpcxpd8loITAM7Ay+INbvTUJJR2dIZmV0PmjGmY/5v4JlunhuinDq1 Zf3S7iYI1lwtINJH9mQc1Spz7GsSYc0tqZ4gs82REzhYgyxVEz5qrThUrzTNwDGXyzwJ sPBVPgZ/xWYVtVUzP81dsAVgJd7Iz8f0i5vcOfmXW6aPLhb+bXeLpnBq/+etOHwddExb Cs3TTNHYa7KHUfMjZFBLko1e+/i6wXRePwmUOk5UL286heDiakYaQMwgnVm18hdBvL48 PExdfGm/xP5+MRnSY1Xh75S+2LqqSTk4eGK/Ka0pTyZ1fZ7HYZTy8DkGHfNzyVfqtm3t Bzgg== X-Gm-Message-State: ALoCoQlq3VepDdyQHqhw03BWUd0SQmt7lUmtK+SjF+fvBXLGebPOawvFRrICrvuEx9Dd7DwlDWm6 X-Received: by 10.236.130.101 with SMTP id j65mr2697116yhi.29.1396019582950; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.229 with SMTP id j92ls994027qgf.78.gmail; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) X-Received: by 10.58.187.78 with SMTP id fq14mr7523861vec.9.1396019582850; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id p4si1291279vem.138.2014.03.28.08.13.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 08:13:02 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id id10so5919908vcb.40 for ; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) X-Received: by 10.58.91.101 with SMTP id cd5mr7475021veb.5.1396019582760; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.12.8 with SMTP id v8csp16212vcv; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) X-Received: by 10.180.98.35 with SMTP id ef3mr48577646wib.39.1396019582050; Fri, 28 Mar 2014 08:13:02 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id ef5si2349505wib.79.2014.03.28.08.13.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Mar 2014 08:13:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WTYSn-0000X3-Tz; Fri, 28 Mar 2014 15:12:57 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-trivial@nongnu.org Subject: [PATCH 2/3] int128.h: Avoid undefined behaviours involving signed arithmetic Date: Fri, 28 Mar 2014 15:12:56 +0000 Message-Id: <1396019577-2013-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396019577-2013-1-git-send-email-peter.maydell@linaro.org> References: <1396019577-2013-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.181 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add casts when we're performing arithmetic on the .hi parts of an Int128, to avoid undefined behaviour. Signed-off-by: Peter Maydell --- 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)