diff mbox series

[3/5] target/loongarch/cpu: Fix coverity errors about excp_names

Message ID 20220713095036.705102-4-yangxiaojuan@loongson.cn
State New
Headers show
Series Fix LoongArch coverity error and cpu name bug | expand

Commit Message

Xiaojuan Yang July 13, 2022, 9:50 a.m. UTC
Fix out-of-bounds errors when access excp_names[] array. the valid
boundary size of excp_names should be 0 to ARRAY_SIZE(excp_names)-1.
However, the general code do not consider the max boundary.

Fix coverity CID: 1489758

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
---
 target/loongarch/cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Richard Henderson July 13, 2022, 4:04 p.m. UTC | #1
On 7/13/22 15:20, Xiaojuan Yang wrote:
> Fix out-of-bounds errors when access excp_names[] array. the valid
> boundary size of excp_names should be 0 to ARRAY_SIZE(excp_names)-1.
> However, the general code do not consider the max boundary.
> 
> Fix coverity CID: 1489758
> 
> Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
> ---
>   target/loongarch/cpu.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

I gave you a reviewed-by for this patch in v1.
You must copy those into v2 so that I don't have to do it again.


r~

> 
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index ed26f9beed..89ea971cde 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -140,7 +140,7 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
>   
>       if (cs->exception_index != EXCCODE_INT) {
>           if (cs->exception_index < 0 ||
> -            cs->exception_index > ARRAY_SIZE(excp_names)) {
> +            cs->exception_index >= ARRAY_SIZE(excp_names)) {
>               name = "unknown";
>           } else {
>               name = excp_names[cs->exception_index];
> @@ -190,8 +190,8 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
>           cause = cs->exception_index;
>           break;
>       default:
> -        qemu_log("Error: exception(%d) '%s' has not been supported\n",
> -                 cs->exception_index, excp_names[cs->exception_index]);
> +        qemu_log("Error: exception(%d) has not been supported\n",
> +                 cs->exception_index);
>           abort();
>       }
>
diff mbox series

Patch

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index ed26f9beed..89ea971cde 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -140,7 +140,7 @@  static void loongarch_cpu_do_interrupt(CPUState *cs)
 
     if (cs->exception_index != EXCCODE_INT) {
         if (cs->exception_index < 0 ||
-            cs->exception_index > ARRAY_SIZE(excp_names)) {
+            cs->exception_index >= ARRAY_SIZE(excp_names)) {
             name = "unknown";
         } else {
             name = excp_names[cs->exception_index];
@@ -190,8 +190,8 @@  static void loongarch_cpu_do_interrupt(CPUState *cs)
         cause = cs->exception_index;
         break;
     default:
-        qemu_log("Error: exception(%d) '%s' has not been supported\n",
-                 cs->exception_index, excp_names[cs->exception_index]);
+        qemu_log("Error: exception(%d) has not been supported\n",
+                 cs->exception_index);
         abort();
     }