From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <rth@twiddle.net>, patches@linaro.org
Subject: [Qemu-devel] [PATCH 3/4] target-arm: A64: Avoid left shifting negative integers in disas_pc_rel_addr
Date: Fri, 6 Feb 2015 14:34:09 +0000 [thread overview]
Message-ID: <1423233250-15853-4-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1423233250-15853-1-git-send-email-peter.maydell@linaro.org>
Shifting a negative integer left is undefined behaviour in C.
Avoid it by assembling and shifting the offset fields as
unsigned values and then sign extending as the final action.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target-arm/translate-a64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index 94b3bf4..68c5b23 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -2662,11 +2662,12 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
{
unsigned int page, rd;
uint64_t base;
- int64_t offset;
+ uint64_t offset;
page = extract32(insn, 31, 1);
/* SignExtend(immhi:immlo) -> offset */
- offset = ((int64_t)sextract32(insn, 5, 19) << 2) | extract32(insn, 29, 2);
+ offset = sextract64(insn, 5, 19);
+ offset = offset << 2 | extract32(insn, 29, 2);
rd = extract32(insn, 0, 5);
base = s->pc - 4;
--
1.9.1
next prev parent reply other threads:[~2015-02-06 14:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-06 14:34 [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings Peter Maydell
2015-02-06 14:34 ` [Qemu-devel] [PATCH 1/4] target-arm: A64: Fix shifts into sign bit Peter Maydell
2015-02-13 3:07 ` Greg Bellows
2015-02-06 14:34 ` [Qemu-devel] [PATCH 2/4] target-arm: A64: Fix handling of rotate in logic_imm_decode_wmask Peter Maydell
2015-02-06 14:34 ` Peter Maydell [this message]
2015-02-06 14:34 ` [Qemu-devel] [PATCH 4/4] target-arm: A64: Avoid signed shifts in disas_ldst_pair() Peter Maydell
2015-02-06 15:57 ` [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings Greg Bellows
2015-02-06 16:09 ` Richard Henderson
2015-02-06 16:20 ` Richard Henderson
2015-02-06 16:43 ` Peter Maydell
2015-02-06 17:30 ` Richard Henderson
2015-02-06 17:37 ` Eric Blake
2015-02-06 17:48 ` Peter Maydell
2015-02-09 9:16 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423233250-15853-4-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=patches@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).