diff mbox

sh4: Fix potential crash in debug code

Message ID 1311188196-2867-1-git-send-email-weil@mail.berlios.de
State Accepted
Headers show

Commit Message

Stefan Weil July 20, 2011, 6:56 p.m. UTC
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.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/sh_intc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Comments

Stefan Hajnoczi July 25, 2011, 10:22 a.m. UTC | #1
On Wed, Jul 20, 2011 at 08:56:35PM +0200, Stefan Weil wrote:
> 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.
> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  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
Stefan Weil Aug. 13, 2011, 9:25 a.m. UTC | #2
Am 20.07.2011 20:56, schrieb 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
>
> If s were NULL, the printf() statement would crash.
> Setting braces fixes this bug.
>
> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
> ---
>   hw/sh_intc.c |    9 +++++----
>   1 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/hw/sh_intc.c b/hw/sh_intc.c
> index 0734da9..f73a4b0 100644
> --- a/hw/sh_intc.c
> +++ b/hw/sh_intc.c
> @@ -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) {
>    

Ping?
Stefan Weil Aug. 27, 2011, 7:27 p.m. UTC | #3
Am 13.08.2011 11:25, schrieb Stefan Weil:
> Am 20.07.2011 20:56, schrieb 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
>>
>> If s were NULL, the printf() statement would crash.
>> Setting braces fixes this bug.
>>
>> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
>> ---
>>   hw/sh_intc.c |    9 +++++----
>>   1 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/sh_intc.c b/hw/sh_intc.c
>> index 0734da9..f73a4b0 100644
>> --- a/hw/sh_intc.c
>> +++ b/hw/sh_intc.c
>> @@ -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) {
>
> 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
Andreas Färber Aug. 28, 2011, 11:13 a.m. UTC | #4
Am 20.07.2011 um 20:56 schrieb 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
>
> If s were NULL, the printf() statement would crash.
> Setting braces fixes this bug.
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>

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.

Reviewed-by: Andreas Färber <andreas.faerber@web.de>

Andreas

> ---
> hw/sh_intc.c |    9 +++++----
> 1 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/hw/sh_intc.c b/hw/sh_intc.c
> index 0734da9..f73a4b0 100644
> --- a/hw/sh_intc.c
> +++ b/hw/sh_intc.c
> @@ -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) {
> -- 
> 1.7.2.5
Stefan Hajnoczi Aug. 29, 2011, 11:39 a.m. UTC | #5
On Wed, Jul 20, 2011 at 08:56:35PM +0200, Stefan Weil wrote:
> 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.
> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  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
diff mbox

Patch

diff --git a/hw/sh_intc.c b/hw/sh_intc.c
index 0734da9..f73a4b0 100644
--- a/hw/sh_intc.c
+++ b/hw/sh_intc.c
@@ -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) {