target/loongarch/op_helper: Fix coverity cond_at_most error
authorXiaojuan Yang <yangxiaojuan@loongson.cn>
Fri, 15 Jul 2022 06:07:40 +0000 (14:07 +0800)
committerRichard Henderson <richard.henderson@linaro.org>
Tue, 19 Jul 2022 16:23:58 +0000 (21:53 +0530)
The boundary size of cpucfg array should be 0 to ARRAY_SIZE(cpucfg)-1.
So, using index bigger than max boundary to access cpucfg[] must be
forbidden.

Fix coverity CID: 1489760

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220715060740.1500628-6-yangxiaojuan@loongson.cn>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
target/loongarch/op_helper.c

index 4b429b6699906f2ce50d6ae21976cbe4b14c8282..568c071601617123a8e4c00836db6b5f98fdf504 100644 (file)
@@ -81,7 +81,7 @@ target_ulong helper_crc32c(target_ulong val, target_ulong m, uint64_t sz)
 
 target_ulong helper_cpucfg(CPULoongArchState *env, target_ulong rj)
 {
-    return rj > 21 ? 0 : env->cpucfg[rj];
+    return rj >= ARRAY_SIZE(env->cpucfg) ? 0 : env->cpucfg[rj];
 }
 
 uint64_t helper_rdtime_d(CPULoongArchState *env)