From patchwork Tue Apr 8 07:04:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 27927 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D480B20447 for ; Tue, 8 Apr 2014 07:15:13 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf2415419obc.9 for ; Tue, 08 Apr 2014 00:15:13 -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=oczIQJq/dURQl+e/er/K6sItU+7/+SZaRWuUfhWoV9c=; b=hIXWMnkrcK4EhN6njt0PcnQLF2XsuGsGArQVV/7XWYk4n3Y1NYOQGz00EnNqlm+xKp +JnureCMUPcx1tT+Ct2aH1NoNm8KxaJuNLgijh874xaN6rq+7F/Ar1YuRVUN7kBntIk2 Vv9JOUwZn18c9aRRuUa39XSGo9SmHiLCNsM5uchYQNemo6My8t3mO0J8rB8TUdHYub1Q JwFUJcRVdvWJWZRoKO2UdgWT71pdwuIw6/PbWC0gaWMxq8v1gq25mTPJgYIV0YuIqwYy AOsPDdtA1Sz4Lrol0BEYJu+GUrfAOO2dk8GEazEjDoSYU2aide0McGc+Ms1QZMF6fyo6 ct/g== X-Gm-Message-State: ALoCoQmfx6mIvB6JycQJwV49Z7LOg/u0ngJszt3wq8T7S9VrzcvG/5ERrJgoXg+yiXc6mN90hHbJ X-Received: by 10.43.4.4 with SMTP id oa4mr936862icb.2.1396941313396; Tue, 08 Apr 2014 00:15:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.202 with SMTP id e68ls114157qgf.12.gmail; Tue, 08 Apr 2014 00:15:13 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr1485139veb.21.1396941313205; Tue, 08 Apr 2014 00:15:13 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id sq9si240314vdc.89.2014.04.08.00.15.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 00:15:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.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.220.174; Received: by mail-vc0-f174.google.com with SMTP id ld13so419995vcb.33 for ; Tue, 08 Apr 2014 00:15:13 -0700 (PDT) X-Received: by 10.52.161.168 with SMTP id xt8mr1475375vdb.23.1396941313135; Tue, 08 Apr 2014 00:15:13 -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 v8csp222797vcv; Tue, 8 Apr 2014 00:15:12 -0700 (PDT) X-Received: by 10.140.27.193 with SMTP id 59mr2246509qgx.18.1396941312361; Tue, 08 Apr 2014 00:15:12 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r70si469799qga.92.2014.04.08.00.15.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 00:15:12 -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]:38478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQFT-0002Zp-QC for patch@linaro.org; Tue, 08 Apr 2014 03:15:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQEb-0001g6-Em for qemu-devel@nongnu.org; Tue, 08 Apr 2014 03:14:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXQEW-0004Mv-Vv for qemu-devel@nongnu.org; Tue, 08 Apr 2014 03:14:17 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:43995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXQEW-0004Me-OH; 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 E539440E32; Tue, 8 Apr 2014 11:14:11 +0400 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id A5C966B0; Tue, 8 Apr 2014 11:04:13 +0400 (MSK) Received: (nullmailer pid 10579 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:07 +0400 Message-Id: <1396940651-10513-8-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 07/11] xbzrle.c: Avoid undefined behaviour with 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.220.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 Use unsigned types for doing bitwise arithmetic in the xzbrle calculations, to avoid undefined behaviour: xbzrle.c:99:49: runtime error: left shift of 72340172838076673 by 7 places cannot be represented in type 'long' Signed-off-by: Peter Maydell Signed-off-by: Michael Tokarev --- xbzrle.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xbzrle.c b/xbzrle.c index fbcb35d..8e220bf 100644 --- a/xbzrle.c +++ b/xbzrle.c @@ -28,7 +28,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, { uint32_t zrun_len = 0, nzrun_len = 0; int d = 0, i = 0; - long res, xor; + long res; uint8_t *nzrun_start = NULL; g_assert(!(((uintptr_t)old_buf | (uintptr_t)new_buf | slen) % @@ -93,9 +93,11 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, /* word at a time for speed, use of 32-bit long okay */ if (!res) { /* truncation to 32-bit long okay */ - long mask = (long)0x0101010101010101ULL; + unsigned long mask = (unsigned long)0x0101010101010101ULL; while (i < slen) { - xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i); + unsigned long xor; + xor = *(unsigned long *)(old_buf + i) + ^ *(unsigned long *)(new_buf + i); if ((xor - mask) & ~xor & (mask << 7)) { /* found the end of an nzrun within the current long */ while (old_buf[i] != new_buf[i]) {