]> Git Repo - qemu.git/commitdiff
disas/arm: Avoid unintended sign extension
authorPeter Maydell <[email protected]>
Fri, 3 Mar 2017 15:50:33 +0000 (15:50 +0000)
committerPeter Maydell <[email protected]>
Tue, 7 Mar 2017 14:33:51 +0000 (14:33 +0000)
When assembling 'given' from the instruction bytes, C's integer
promotion rules mean we may promote an unsigned char to a signed
integer before shifting it, and then sign extend to a 64-bit long,
which can set the high bits of the long.  The code doesn't in fact
care about the high bits if the long is 64 bits, but this is
surprising, so don't do it.

(Spotted by Coverity, CID 1005404.)

Signed-off-by: Peter Maydell <[email protected]>
Message-id: 1488556233[email protected]

disas/arm.c

index 93c650344cec2f6a8220a41c4293bbc769cd7f93..27396dd3e16eb2931ec4586843e3ec2eb2e9ec70 100644 (file)
@@ -3901,9 +3901,9 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
 
       status = info->read_memory_func (pc, (bfd_byte *)b, 4, info);
       if (little)
-       given = (b[0]) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
+       given = (b[0]) | (b[1] << 8) | (b[2] << 16) | ((unsigned)b[3] << 24);
       else
-       given = (b[3]) | (b[2] << 8) | (b[1] << 16) | (b[0] << 24);
+       given = (b[3]) | (b[2] << 8) | (b[1] << 16) | ((unsigned)b[0] << 24);
     }
   else
     {
This page took 0.031277 seconds and 4 git commands to generate.