summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPeter Maydell2014-03-28 16:12:56 +0100
committerMichael Tokarev2014-04-18 08:33:36 +0200
commit423d00c857ebc814ef6b5fc63f1d6c595cdc005d (patch)
treec032e6853c2ad0239eb3bcabf1a960638db6a523 /include
parenthw/ide/ahci.c: Avoid shift left into sign bit (diff)
downloadqemu-423d00c857ebc814ef6b5fc63f1d6c595cdc005d.tar.gz
qemu-423d00c857ebc814ef6b5fc63f1d6c595cdc005d.tar.xz
qemu-423d00c857ebc814ef6b5fc63f1d6c595cdc005d.zip
int128.h: Avoid undefined behaviours involving signed arithmetic
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> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'include')
-rw-r--r--include/qemu/int128.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/qemu/int128.h b/include/qemu/int128.h
index 9ed47aafd3..f59703143a 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)