mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 18:23:57 -06:00
disas/m68k: Avoid unintended sign extension in get_field()
In get_field(), we take an 'unsigned char' value and shift it left, which implicitly promotes it to 'signed int', before ORing it into an 'unsigned long' type. If 'unsigned long' is 64 bits then this will result in a sign extension and the top 32 bits of the result will be 1s. Add explicit casts to unsigned long before shifting to prevent this. (Spotted by Coverity, CID 715697.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-id: 1488556233-31246-4-git-send-email-peter.maydell@linaro.org
This commit is contained in:
parent
3f168b5d35
commit
2e3883d03d
1 changed files with 3 additions and 2 deletions
|
@ -4685,10 +4685,11 @@ get_field (const unsigned char *data, enum floatformat_byteorders order,
|
|||
/* This is the last byte; zero out the bits which are not part of
|
||||
this field. */
|
||||
result |=
|
||||
(*(data + cur_byte) & ((1 << (len - cur_bitshift)) - 1))
|
||||
(unsigned long)(*(data + cur_byte)
|
||||
& ((1 << (len - cur_bitshift)) - 1))
|
||||
<< cur_bitshift;
|
||||
else
|
||||
result |= *(data + cur_byte) << cur_bitshift;
|
||||
result |= (unsigned long)*(data + cur_byte) << cur_bitshift;
|
||||
cur_bitshift += FLOATFORMAT_CHAR_BIT;
|
||||
if (order == floatformat_little)
|
||||
++cur_byte;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue