flash/nor/str7x: fix undefined behaviour

Shifting 32 bit signed variables by 31 bits is undefined behaviour

Change-Id: Iec61a98eecd6657ff6ba1dcad6fff76052c917e3
Signed-off-by: Mark O'Donovan <shiftee@posteo.net>
Reviewed-on: https://review.openocd.org/c/openocd/+/9497
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Mark O'Donovan
2026-03-09 21:48:16 +00:00
committed by Antonio Borneo
parent 4e23bf155f
commit 92dc88978a

View File

@@ -736,7 +736,7 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command)
target_read_u32(target, str7x_get_flash_adr(bank, FLASH_NVAPR1), &reg);
protection_regs = ~(reg >> 16);
while (((protection_regs) != 0) && (protection_level < 16)) {
while ((protection_regs != 0) && (protection_level < 16)) {
protection_regs >>= 1;
protection_level++;
}
@@ -753,7 +753,7 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command)
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), flash_cmd);
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), 0x4010DFBC);
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_DR0),
~(1 << (15 + protection_level)));
~(1U << (15 + protection_level)));
flash_cmd = FLASH_SPR | FLASH_WMS;
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), flash_cmd);
}