Skip to contentSkip to conversation

sh4: Fix potential crash in debug code

PATCH Applied Stefan Weil 4 participants 8 messages Jul 20, 2011 – Aug 29, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh4: Fix potential crash in debug code

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

---
 hw/sh_intc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
hw/sh_intc.c +5 -4
index 0734da9..f73a4b0 100644
@@ -382,13 +382,14 @@ void sh_intc_register_sources(struct intc_desc *desc,
 
 	sh_intc_register_source(desc, vect->enum_id, groups, nr_groups);
 	s = sh_intc_source(desc, vect->enum_id);
-	if (s)
-	    s->vect = vect->vect;
+        if (s) {
+            s->vect = vect->vect;
 
 #ifdef DEBUG_INTC_SOURCES
-	printf("sh_intc: registered source %d -> 0x%04x (%d/%d)\n",
-	       vect->enum_id, s->vect, s->enable_count, s->enable_max);
+            printf("sh_intc: registered source %d -> 0x%04x (%d/%d)\n",
+                   vect->enum_id, s->vect, s->enable_count, s->enable_max);
 #endif
+        }
     }
 
     if (groups) {
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH 1/1 tcg/mips: Fix regression caused by typo (copy + paste bug)

cppcheck reports an error:
qemu/tcg/mips/tcg-target.c:1487: error: Invalid number of character (()

The unpatched code won't compile on mips hosts starting with commit cea5f9a28faa528b6b1b117c9ab2d8828f473fef.

---
 tcg/mips/tcg-target.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tcg/mips/tcg-target.c +1 -1
index 12ff9d5..a33d21f 100644
@@ -1484,7 +1484,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
     }
 
     /* Call generated code */
-    tcg_out_opc_reg(s, OPC_JR, 0, tcg_target_call_iarg_regs[1]), 0);
+    tcg_out_opc_reg(s, OPC_JR, 0, tcg_target_call_iarg_regs[1], 0);
     tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
     tb_ret_addr = s->code_ptr;
 
Signature · 1 line
1.7.2.5
Applied
#2 lore raw

Re: [Qemu-trivial] [PATCH] tcg/mips: Fix regression caused by typo (copy + paste bug)

Thanks, applied.

Quoted 29 lines · Stefan Weil

cppcheck reports an error:
qemu/tcg/mips/tcg-target.c:1487: error: Invalid number of character (()

The unpatched code won't compile on mips hosts starting with commit cea5f9a28faa528b6b1b117c9ab2d8828f473fef.

---
 tcg/mips/tcg-target.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
tcg/mips/tcg-target.c +1 -2
index 12ff9d5..a33d21f 100644
@@ -1484,7 +1484,7 @@ static void tcg_target_qemu_prologue(TCGContext *s)
     }
 
     /* Call generated code */
-    tcg_out_opc_reg(s, OPC_JR, 0, tcg_target_call_iarg_regs[1]), 0);
+    tcg_out_opc_reg(s, OPC_JR, 0, tcg_target_call_iarg_regs[1], 0);
     tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
     tb_ret_addr = s->code_ptr;
 
--

1.7.2.5

#3 lore raw
In reply to Stefan Weil
Quoted 5 lines · Stefan Weil

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

Quoted 7 lines

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

---
 hw/sh_intc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Aurelien Jarno is listed as active maintainer for this code. Patches should go through him.

Stefan

#4 lore raw
In reply to Stefan Weil

Am 20.07.2011 20:56, schrieb Stefan Weil:

Quoted 27 lines

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

---
  hw/sh_intc.c |    9 +++++----
  1 files changed, 5 insertions(+), 4 deletions(-)
hw/sh_intc.c +2 -2
index 0734da9..f73a4b0 100644
@@ -382,13 +382,14 @@ void sh_intc_register_sources(struct intc_desc *desc,
 
  	sh_intc_register_source(desc, vect->enum_id, groups, nr_groups);
  	s = sh_intc_source(desc, vect->enum_id);
-	if (s)
-	    s->vect = vect->vect;
+        if (s) {
+            s->vect = vect->vect;
 

hw/sh_intc.c void sh_intc_register_sources(struct intc_desc *desc, · line 395

Quoted 10 lines
hw/sh_intc.c +3 -2
  #ifdef DEBUG_INTC_SOURCES
-	printf("sh_intc: registered source %d ->  0x%04x (%d/%d)\n",
-	       vect->enum_id, s->vect, s->enable_count, s->enable_max);
+            printf("sh_intc: registered source %d ->  0x%04x (%d/%d)\n",
+                   vect->enum_id, s->vect, s->enable_count, s->enable_max);
  #endif
+        }
      }
 
      if (groups) {

Ping?

#5 lore raw

Am 13.08.2011 11:25, schrieb Stefan Weil:

Quoted 39 lines

Am 20.07.2011 20:56, schrieb Stefan Weil:

Quoted 38 lines

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

---
  hw/sh_intc.c |    9 +++++----
  1 files changed, 5 insertions(+), 4 deletions(-)
hw/sh_intc.c +5 -4
index 0734da9..f73a4b0 100644
@@ -382,13 +382,14 @@ void sh_intc_register_sources(struct intc_desc 
 *desc,
 
      sh_intc_register_source(desc, vect->enum_id, groups, nr_groups);
      s = sh_intc_source(desc, vect->enum_id);
-    if (s)
-        s->vect = vect->vect;
+        if (s) {
+            s->vect = vect->vect;
 
  #ifdef DEBUG_INTC_SOURCES
-    printf("sh_intc: registered source %d ->  0x%04x (%d/%d)\n",
-           vect->enum_id, s->vect, s->enable_count, s->enable_max);
+            printf("sh_intc: registered source %d ->  0x%04x 
 (%d/%d)\n",
+                   vect->enum_id, s->vect, s->enable_count, 
 s->enable_max);
  #endif
+        }
      }
Quoted 3 lines
Quoted 1 line
      if (groups) {

Ping?

Please add the patch to the trivial queue. More than a month time for review and comments should be sufficient for trivial patches.

Thanks,
Stefan

Reviewed-by on v1 1/1
#6 lore raw
In reply to Stefan Weil

Am 20.07.2011 um 20:56 schrieb Stefan Weil:

Quoted 9 lines

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

Apart from the stated addition of brackets, this reindents the bracketed block, replacing tabs with spaces. Reindenting further code or introducing a trace point is beyond the scope of a trivial bugfix, so patch looks fine to me.

Andreas

Quoted 32 lines

---
hw/sh_intc.c | 9 +++++----

1 files changed, 5 insertions(+), 4 deletions(-)
hw/sh_intc.c +5 -4
index 0734da9..f73a4b0 100644
@@ -382,13 +382,14 @@ void sh_intc_register_sources(struct intc_desc  
 *desc,
 
 	sh_intc_register_source(desc, vect->enum_id, groups, nr_groups);
 	s = sh_intc_source(desc, vect->enum_id);
-	if (s)
-	    s->vect = vect->vect;
+        if (s) {
+            s->vect = vect->vect;
 
 #ifdef DEBUG_INTC_SOURCES
-	printf("sh_intc: registered source %d -> 0x%04x (%d/%d)\n",
-	       vect->enum_id, s->vect, s->enable_count, s->enable_max);
+            printf("sh_intc: registered source %d -> 0x%04x (%d/%d) 
 \n",
+                   vect->enum_id, s->vect, s->enable_count, s- 
 >enable_max);
 #endif
+        }
    }

    if (groups) {
Signature · 1 line
1.7.2.5
#7 lore raw
In reply to Stefan Weil
Quoted 5 lines · Stefan Weil

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
s - otherwise it is redundant to check if s is null at line 385

Quoted 7 lines

If s were NULL, the printf() statement would crash. Setting braces fixes this bug.

---
 hw/sh_intc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches

Stefan