summaryrefslogtreecommitdiffstats
path: root/disas
diff options
context:
space:
mode:
authorPeter Maydell2017-03-03 16:50:31 +0100
committerPeter Maydell2017-03-07 15:33:51 +0100
commit1d153a3388b150b8aeedde32242db86b79c45473 (patch)
tree64fe1731167f5d3c143b0f40b318b23fbc2a6148 /disas
parentdisas/m68k: Avoid unintended sign extension in get_field() (diff)
downloadqemu-1d153a3388b150b8aeedde32242db86b79c45473.tar.gz
qemu-1d153a3388b150b8aeedde32242db86b79c45473.tar.xz
qemu-1d153a3388b150b8aeedde32242db86b79c45473.zip
disas/microblaze: Avoid unintended sign extension
In read_insn_microblaze() we assemble 4 bytes into an 'unsigned long'. If 'unsigned long' is 64 bits and the high byte has its top bit set, then C's implicit conversion from 'unsigned char' to 'int' for the shift will result in an unintended sign extension which sets the top 32 bits in 'inst'. Add casts to prevent this. (Spotted by Coverity, CID 1005401.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Message-id: 1488556233-31246-5-git-send-email-peter.maydell@linaro.org
Diffstat (limited to 'disas')
-rw-r--r--disas/microblaze.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/disas/microblaze.c b/disas/microblaze.c
index 91b30acbe1..407c0a3ffa 100644
--- a/disas/microblaze.c
+++ b/disas/microblaze.c
@@ -748,9 +748,11 @@ read_insn_microblaze (bfd_vma memaddr,
}
if (info->endian == BFD_ENDIAN_BIG)
- inst = (ibytes[0] << 24) | (ibytes[1] << 16) | (ibytes[2] << 8) | ibytes[3];
+ inst = ((unsigned)ibytes[0] << 24) | (ibytes[1] << 16)
+ | (ibytes[2] << 8) | ibytes[3];
else if (info->endian == BFD_ENDIAN_LITTLE)
- inst = (ibytes[3] << 24) | (ibytes[2] << 16) | (ibytes[1] << 8) | ibytes[0];
+ inst = ((unsigned)ibytes[3] << 24) | (ibytes[2] << 16)
+ | (ibytes[1] << 8) | ibytes[0];
else
abort ();