Skip to content

Commit e90ef39

Browse files
authored
Use bitwise OR with mask for sign extension (#2371)
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
1 parent 3f87ce0 commit e90ef39

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/SH/SHDisassembler.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,13 +1459,13 @@ static bool decode_long(uint32_t code, uint64_t address, MCInst *MI,
14591459
if (code & 0x00010000) {
14601460
// movi20s #imm,
14611461
imm <<= 8;
1462-
if (imm >= 1 << 27)
1463-
imm = -((1 << 28) - imm);
1462+
if (imm & (1 << (28 - 1)))
1463+
imm |= ~((1 << 28) - 1);
14641464
insn = SH_INS_MOVI20S;
14651465
} else {
14661466
// MOVI20
1467-
if (imm >= 1 << 19)
1468-
imm = -((1 << 20) - imm);
1467+
if (imm & (1 << (28 - 1)))
1468+
imm |= ~((1 << 20) - 1);
14691469
insn = SH_INS_MOVI20;
14701470
}
14711471
set_imm(info, 0, imm);

0 commit comments

Comments
 (0)