From: Peter Maydell <[email protected]>

In prop_marchid_set() we set mxlen to either 32 or 64, and then
calculate
 invalid_val = 1LL << (mxlen - 1);

which shifts the signed value 1LL up into its sign bit when mxlen is
64, which Coverity complains about.

This is not UB for QEMU because we use -fwrapv, but it makes more
sense to use an explicitly unsigned 1ULL here when we clearly want to
be treating it as an unsigned value and the 'invalid_val' variable is
of type uint64_t.

Resolves: Coverity CID 1547552
Fixes: d6a427e2c0b24 ("target/riscv/cpu.c: restrict 'marchid' value")
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Chao Liu <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
---
 target/riscv/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index c162d2803367..5a0529fbdade 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2317,7 +2317,7 @@ static void prop_marchid_set(Object *obj, Visitor *v, 
const char *name,
         g_assert_not_reached();
     }
 
-    invalid_val = 1LL << (mxlen - 1);
+    invalid_val = 1ULL << (mxlen - 1);
 
     if (value == invalid_val) {
         error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
-- 
2.55.0


Reply via email to