From: Peter Maydell Date: Tue, 23 Jul 2024 17:24:31 +0000 (+0100) Subject: target/sh4: Avoid shift into sign bit in update_itlb_use() X-Git-Tag: qemu-xen-4.20.0~44^2~1 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=525650cd71104c046e4260b5acaeb275f520d5c0;p=qemu-xen.git target/sh4: Avoid shift into sign bit in update_itlb_use() 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 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Yoshinori Sato Message-id: 20240723172431.1757296-1-peter.maydell@linaro.org --- diff --git a/target/sh4/helper.c b/target/sh4/helper.c index 6702910627..9659c69550 100644 --- a/target/sh4/helper.c +++ b/target/sh4/helper.c @@ -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: