diff mbox

darwin-user: Remove unneeded null pointer check

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

Commit Message

Stefan Weil April 3, 2011, 4:22 p.m. UTC
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.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 darwin-user/commpage.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Aurelien Jarno April 27, 2011, 2:28 p.m. UTC | #1
On Sun, Apr 03, 2011 at 06:22:45PM +0200, Stefan Weil wrote:
> 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.
> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  darwin-user/commpage.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied.

> diff --git a/darwin-user/commpage.c b/darwin-user/commpage.c
> index f6aa71e..cc29bdd 100644
> --- a/darwin-user/commpage.c
> +++ b/darwin-user/commpage.c
> @@ -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);
> -- 
> 1.7.2.5
> 
> 
>
diff mbox

Patch

diff --git a/darwin-user/commpage.c b/darwin-user/commpage.c
index f6aa71e..cc29bdd 100644
--- a/darwin-user/commpage.c
+++ b/darwin-user/commpage.c
@@ -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);