Skip to content

Commit ec6411a

Browse files
danielhbalistair23
authored andcommitted
target/riscv/csr.c: fix OVERFLOW_BEFORE_WIDEN in rmw_sctrdepth()
Coverity found the following issue: >>> CID 1593156: Integer handling issues (OVERFLOW_BEFORE_WIDEN) >>> Potentially overflowing expression "0x10 << depth" with type "int" (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned). 4299 depth = 16 << depth; Fix it by forcing the expression to be 64 bits wide by using '16ULL'. Resolves: Coverity CID 1593156 Fixes: c48bd18 ("target/riscv: Add support for Control Transfer Records extension CSRs.") Signed-off-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent 3ea8fb5 commit ec6411a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

target/riscv/csr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4302,7 +4302,7 @@ static RISCVException rmw_sctrdepth(CPURISCVState *env, int csrno,
43024302
}
43034303

43044304
/* Update sctrstatus.WRPTR with a legal value */
4305-
depth = 16 << depth;
4305+
depth = 16ULL << depth;
43064306
env->sctrstatus =
43074307
env->sctrstatus & (~SCTRSTATUS_WRPTR_MASK | (depth - 1));
43084308
}

0 commit comments

Comments
 (0)