Skip to content

Commit

Permalink
Use bitwise OR with mask for sign extension
Browse files Browse the repository at this point in the history
Sign extend using bitwise OR with mask, instead of unary minus.
Fixes error when building for UWP with Security Development Lifecycle (SDL).
See https://learn.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=msvc-170
  • Loading branch information
lhsazevedo committed Jun 13, 2024
1 parent fe60b13 commit efd4047
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arch/SH/SHDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,13 +1459,13 @@ static bool decode_long(uint32_t code, uint64_t address, MCInst *MI,
if (code & 0x00010000) {
// movi20s #imm,
imm <<= 8;
if (imm >= 1 << 27)
imm = -((1 << 28) - imm);
if (imm & (1 << (28 - 1)))
imm |= ~((1 << 28) - 1);
insn = SH_INS_MOVI20S;
} else {
// MOVI20
if (imm >= 1 << 19)
imm = -((1 << 20) - imm);
if (imm & (1 << (28 - 1)))
imm |= ~((1 << 20) - 1);
insn = SH_INS_MOVI20;
}
set_imm(info, 0, imm);
Expand Down

0 comments on commit efd4047

Please sign in to comment.