Skip to contentSkip to conversation

darwin-user: Remove unneeded null pointer check

PATCH Applied Stefan Weil 2 participants 2 messages Apr 3, 2011 – Apr 27, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 darwin-user: Remove unneeded null pointer check

cppcheck reports this error:

commpage.c:223: error: Possible null pointer dereference:
value - otherwise it is redundant to check if value is null at line 214

The null pointer check in line 214 is indeed not needed. If value were null, the code would crash in line 223. See do_compare_and_swap64 were for a reference.

---
 darwin-user/commpage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
darwin-user/commpage.c +1 -1
index f6aa71e..cc29bdd 100644
@@ -211,7 +211,7 @@ void do_compare_and_swap32(void *cpu_env, int num)
     uint32_t *value = (uint32_t*)((CPUX86State*)cpu_env)->regs[R_ECX];
     DPRINTF("commpage: compare_and_swap32(%x,new,%p)\n", old, value);
 
-    if(value && old == tswap32(*value))
+    if(old == tswap32(*value))
     {
         uint32_t new = ((CPUX86State*)cpu_env)->regs[R_EDX];
         *value = tswap32(new);
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 5 lines · Stefan Weil

cppcheck reports this error:

commpage.c:223: error: Possible null pointer dereference:
value - otherwise it is redundant to check if value is null at line 214

Quoted 8 lines

The null pointer check in line 214 is indeed not needed. If value were null, the code would crash in line 223. See do_compare_and_swap64 were for a reference.

---
 darwin-user/commpage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied.

Quoted 18 lines
darwin-user/commpage.c +1 -1
index f6aa71e..cc29bdd 100644
@@ -211,7 +211,7 @@ void do_compare_and_swap32(void *cpu_env, int num)
     uint32_t *value = (uint32_t*)((CPUX86State*)cpu_env)->regs[R_ECX];
     DPRINTF("commpage: compare_and_swap32(%x,new,%p)\n", old, value);
 
-    if(value && old == tswap32(*value))
+    if(old == tswap32(*value))
     {
         uint32_t new = ((CPUX86State*)cpu_env)->regs[R_EDX];
         *value = tswap32(new);
Signature · 1 line
1.7.2.5
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net