From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, patches@linaro.org
Subject: [Qemu-devel] [PATCH 2/3] int128.h: Avoid undefined behaviours involving signed arithmetic
Date: Fri, 28 Mar 2014 15:12:56 +0000 [thread overview]
Message-ID: <1396019577-2013-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1396019577-2013-1-git-send-email-peter.maydell@linaro.org>
Add casts when we're performing arithmetic on the .hi parts of an
Int128, to avoid undefined behaviour.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/qemu/int128.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 9ed47aa..f597031 100644
--- a/include/qemu/int128.h
+++ b/include/qemu/int128.h
@@ -53,7 +53,7 @@ static inline Int128 int128_rshift(Int128 a, int n)
if (n >= 64) {
return (Int128) { h, h >> 63 };
} else {
- return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), h };
+ return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
}
}
@@ -78,7 +78,7 @@ static inline Int128 int128_neg(Int128 a)
static inline Int128 int128_sub(Int128 a, Int128 b)
{
- return (Int128){ a.lo - b.lo, a.hi - b.hi - (a.lo < b.lo) };
+ return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };
}
static inline bool int128_nonneg(Int128 a)
--
1.9.0
next prev parent reply other threads:[~2014-03-28 15:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-28 15:12 [Qemu-devel] [PATCH 0/3] More fixes for undefined behaviour Peter Maydell
2014-03-28 15:12 ` [Qemu-devel] [PATCH 1/3] hw/ide/ahci.c: Avoid shift left into sign bit Peter Maydell
2014-04-06 7:10 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-03-28 15:12 ` Peter Maydell [this message]
2014-04-06 7:09 ` [Qemu-devel] [Qemu-trivial] [PATCH 2/3] int128.h: Avoid undefined behaviours involving signed arithmetic Michael Tokarev
2014-04-06 10:18 ` Peter Maydell
2014-04-06 14:13 ` Michael Tokarev
2014-04-06 14:58 ` Peter Maydell
2014-04-06 15:27 ` Peter Maydell
2014-04-07 14:25 ` Richard Henderson
2014-04-07 14:47 ` Peter Maydell
2014-04-07 15:49 ` Markus Armbruster
2014-04-07 14:56 ` Avi Kivity
2014-04-07 15:17 ` Peter Maydell
2014-04-07 15:22 ` Avi Kivity
2014-03-28 15:12 ` [Qemu-devel] [PATCH 3/3] xbzrle.c: Avoid undefined behaviour with " Peter Maydell
2014-04-06 14:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
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=1396019577-2013-3-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=patches@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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).