]> git.proxmox.com Git - qemu.git/commitdiff
sd/pl181.c: Avoid undefined shift behaviour in RWORD macro
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 27 Jun 2013 14:03:51 +0000 (15:03 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 15 Jul 2013 15:17:30 +0000 (16:17 +0100)
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 <peter.maydell@linaro.org>
Message-id: 1372341831-4264-1-git-send-email-peter.maydell@linaro.org

hw/sd/pl181.c

index 4b1723418d3238f34cf6b9bd35f0a1107d97f934..f5eb1e40120c6a9572b48ba3d135b7c9d9734ab3 100644 (file)
@@ -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;