]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
target/sh4: Avoid shift into sign bit in update_itlb_use()
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 23 Jul 2024 17:24:31 +0000 (18:24 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 29 Jul 2024 16:00:20 +0000 (17:00 +0100)
In update_itlb_use() the variables or_mask and and_mask are uint8_t,
which means that in expressions like "and_mask << 24" the usual C
arithmetic conversions will result in the shift being done as a
signed int type, and so we will shift into the sign bit. For QEMU
this isn't undefined behaviour because we use -fwrapv; but we can
avoid it anyway by using uint32_t types for or_mask and and_mask.

Resolves: Coverity CID 1547628
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Yoshinori Sato <ysato@users.sourceforge.jp>
Message-id: 20240723172431.1757296-1-peter.maydell@linaro.org

target/sh4/helper.c

index 670291062778ebbf099b9400ca268eaa5a37df01..9659c6955040d2f48c57ced339c2f4ad1d34f7fd 100644 (file)
@@ -187,7 +187,7 @@ void superh_cpu_do_interrupt(CPUState *cs)
 
 static void update_itlb_use(CPUSH4State * env, int itlbnb)
 {
-    uint8_t or_mask = 0, and_mask = (uint8_t) - 1;
+    uint32_t or_mask = 0, and_mask = 0xff;
 
     switch (itlbnb) {
     case 0: