From patchwork Thu Jun 27 14:03:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18160 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A7FDF25E0D for ; Thu, 27 Jun 2013 14:03:55 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id z20sf1261540yhz.7 for ; Thu, 27 Jun 2013 07:03:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=s64huMSPkfR9Nv4yTcHdy6K23ixlByR5aPPyz1gKvVk=; b=VL1tP75V/6c5WFlg8O2ryXq6oaWMjLA0f8jP+Qx2txo7Z82Wf8CWYVYFZSi5x+xEXS l8wxIcOU240BhwJXmP0S8Olng8XO4jkIdEz2LLQxuOQCkw7tKLq1ij9oArXub7ZILfUC 96/yM4/84fRVnB/ldd2dAAD3bBedyDhv90Eq27E7NDjPoWsMosIxy+hv/jFCANcoK4D8 N+Xil0oLuPG59TH2WFJaG8cgeu2qShI0phy+e6BbcjctV8KvTbECIYP2shP/rq6pf+8H rYHFwOtk2Rcmook3GTgI7uS07k5gTeOcH9Ti3oFEP579zS8F4osxTrC6Y7/9UJNeEJt8 qg3w== X-Received: by 10.58.123.8 with SMTP id lw8mr937163veb.37.1372341834890; Thu, 27 Jun 2013 07:03:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.97.195 with SMTP id ec3ls813265qeb.13.gmail; Thu, 27 Jun 2013 07:03:54 -0700 (PDT) X-Received: by 10.52.92.135 with SMTP id cm7mr2996407vdb.36.1372341834735; Thu, 27 Jun 2013 07:03:54 -0700 (PDT) Received: from mail-vb0-f47.google.com (mail-vb0-f47.google.com [209.85.212.47]) by mx.google.com with ESMTPS id tf3si808290vec.106.2013.06.27.07.03.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Jun 2013 07:03:54 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.47 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.47; Received: by mail-vb0-f47.google.com with SMTP id x14so654945vbb.6 for ; Thu, 27 Jun 2013 07:03:54 -0700 (PDT) X-Received: by 10.58.251.144 with SMTP id zk16mr3512792vec.37.1372341834635; Thu, 27 Jun 2013 07:03:54 -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.58.165.8 with SMTP id yu8csp149814veb; Thu, 27 Jun 2013 07:03:54 -0700 (PDT) X-Received: by 10.194.176.41 with SMTP id cf9mr6218418wjc.66.1372341833292; Thu, 27 Jun 2013 07:03:53 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id pa4si1106427wjb.26.2013.06.27.07.03.52 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Jun 2013 07:03:53 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1UsCnf-00017F-SV; Thu, 27 Jun 2013 15:03:51 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH] sd/pl181.c: Avoid undefined shift behaviour in RWORD macro Date: Thu, 27 Jun 2013 15:03:51 +0100 Message-Id: <1372341831-4264-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQl08wHN39bwSEbv3uQQTnLuqow84Xqe4tP81pgp7+VJx4W7+2KF/IARExLV8bCuo+MJFOVr X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.47 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 a cast to avoid potentially shifting into the sign bit of a signed value, which is undefined behaviour in C. (Detected with clang's -fsanitize=undefined.) Signed-off-by: Peter Maydell --- Not the only problem clang detects by a long shot. I don't know if we even want to try to fix the warnings about loads of 32 bit values from misaligned addresses, but there are some more shift related warnings that we might as well zap. hw/sd/pl181.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index e08fd04..e5128c4 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -175,7 +175,7 @@ static void pl181_send_command(pl181_state *s) if (rlen < 0) goto error; if (s->cmd & PL181_CMD_RESPONSE) { -#define RWORD(n) ((response[n] << 24) | (response[n + 1] << 16) \ +#define RWORD(n) (((uint32_t)response[n] << 24) | (response[n + 1] << 16) \ | (response[n + 2] << 8) | response[n + 3]) if (rlen == 0 || (rlen == 4 && (s->cmd & PL181_CMD_LONGRESP))) goto error;