Patchwork lib: fwts_release: check *str rather than str

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 8:20 a.m.
Message ID <1367914812-16805-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/242073/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 8:20 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997338: Dereference before null check (REVERSE_NULL)

Should be checking if *str is not end of string rather than
if str is a valid pointer (typo).

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_release.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Alex Hung - May 9, 2013, 5:22 a.m.
On 05/07/2013 04:20 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997338: Dereference before null check (REVERSE_NULL)
>
> Should be checking if *str is not end of string rather than
> if str is a valid pointer (typo).
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_release.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_release.c b/src/lib/src/fwts_release.c
> index 5c06747..c428856 100644
> --- a/src/lib/src/fwts_release.c
> +++ b/src/lib/src/fwts_release.c
> @@ -38,7 +38,7 @@ static void fwts_release_field_get(char *needle, char *delimiter, char *text, ch
>   	while (*str == ' ')
>   		str++;
>
> -	if (str)
> +	if (*str)
>   		*field = strdup(str);
>   }
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:33 a.m.
On Tue, May 7, 2013 at 4:20 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997338: Dereference before null check (REVERSE_NULL)
>
> Should be checking if *str is not end of string rather than
> if str is a valid pointer (typo).
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_release.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_release.c b/src/lib/src/fwts_release.c
> index 5c06747..c428856 100644
> --- a/src/lib/src/fwts_release.c
> +++ b/src/lib/src/fwts_release.c
> @@ -38,7 +38,7 @@ static void fwts_release_field_get(char *needle, char *delimiter, char *text, ch
>         while (*str == ' ')
>                 str++;
>
> -       if (str)
> +       if (*str)
>                 *field = strdup(str);
>  }
>
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_release.c b/src/lib/src/fwts_release.c
index 5c06747..c428856 100644
--- a/src/lib/src/fwts_release.c
+++ b/src/lib/src/fwts_release.c
@@ -38,7 +38,7 @@  static void fwts_release_field_get(char *needle, char *delimiter, char *text, ch
 	while (*str == ' ')
 		str++;
 
-	if (str)
+	if (*str)
 		*field = strdup(str);
 }