From b790a3376929a5efca78a704cd318c64aec93a4d Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Tue, 9 Jan 2024 05:41:55 +0800 Subject: [PATCH] Fix undefined behavior in RV_MARCHID definition The RV_MARCHID macro is defined using a left shift operation without explicitly specifying the type of the constant. This can lead to undefined behavior, specifically a shift too many bits issue. Modify the RV_MARCHID definition to use the ULL suffix for the constant, ensuring it is treated as an unsigned long long. This eliminates the undefined behavior. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index f9bc178..b6238bf 100644 --- a/main.c +++ b/main.c @@ -185,7 +185,7 @@ static inline sbi_ret_t handle_sbi_ecall_RST(vm_t *vm, int32_t fid) } #define RV_MVENDORID 0x12345678 -#define RV_MARCHID ((1 << 31) | 1) +#define RV_MARCHID ((1ULL << 31) | 1) #define RV_MIMPID 1 static inline sbi_ret_t handle_sbi_ecall_BASE(vm_t *vm, int32_t fid)