* [Qemu-devel] [PATCH] sd/pl181.c: Avoid undefined shift behaviour in RWORD macro
@ 2013-06-27 14:03 Peter Maydell
0 siblings, 0 replies; only message in thread
From: Peter Maydell @ 2013-06-27 14:03 UTC (permalink / raw)
To: qemu-devel; +Cc: patches
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>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-06-27 14:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-27 14:03 [Qemu-devel] [PATCH] sd/pl181.c: Avoid undefined shift behaviour in RWORD macro Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).