Received: from eggs.gnu.org ([2001:4830:134:3::10]:42771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsCnq-00070s-Lf for qemu-devel@nongnu.org; Thu, 27 Jun 2013 10:04:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsCni-0005sb-Dl for qemu-devel@nongnu.org; Thu, 27 Jun 2013 10:04:02 -0400 Received: from 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]:58291 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsCni-0005sI-7R for qemu-devel@nongnu.org; Thu, 27 Jun 2013 10:03:54 -0400 From: Peter Maydell Date: Thu, 27 Jun 2013 15:03:51 +0100 Message-Id: <1372341831-4264-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH] sd/pl181.c: Avoid undefined shift behaviour in RWORD macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: patches@linaro.org 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; -- 1.7.9.5