diff mbox series

lib: fwts_cpu: only assign a string if it has not yet been assigned

Message ID 20190610111036.22630-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_cpu: only assign a string if it has not yet been assigned | expand

Commit Message

Colin Ian King June 10, 2019, 11:10 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

This just cleans up some static analysis warnings

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alex Hung June 10, 2019, 8:29 p.m. UTC | #1
On 2019-06-10 4:10 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> This just cleans up some static analysis warnings
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_cpu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index e866d1dc..71e0e877 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -151,7 +151,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  
>  		found = true;
>  
> -		if (!strncmp(buffer, "vendor_id", 9)) {
> +		if (!cpu->vendor_id && !strncmp(buffer, "vendor_id", 9)) {
>  			cpu->vendor_id = strdup(ptr);
>  			continue;
>  		}
> @@ -159,7 +159,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  			sscanf(ptr, "%d", &cpu->x86);
>  			continue;
>  		}
> -		if (!strncmp(buffer, "model name", 10)) {
> +		if (!cpu->model_name && !strncmp(buffer, "model name", 10)) {
>  			cpu->model_name = strdup(ptr);
>  			continue;
>  		}
> @@ -171,7 +171,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  			sscanf(ptr, "%d", &cpu->stepping);
>  			continue;
>  		}
> -		if (!strncmp(buffer, "flags", 5)) {
> +		if (!cpu->flags && !strncmp(buffer, "flags", 5)) {
>  			cpu->flags = strdup(ptr);
>  			continue;
>  		}
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu June 11, 2019, 5:44 a.m. UTC | #2
On 6/10/19 7:10 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> This just cleans up some static analysis warnings
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_cpu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index e866d1dc..71e0e877 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -151,7 +151,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  
>  		found = true;
>  
> -		if (!strncmp(buffer, "vendor_id", 9)) {
> +		if (!cpu->vendor_id && !strncmp(buffer, "vendor_id", 9)) {
>  			cpu->vendor_id = strdup(ptr);
>  			continue;
>  		}
> @@ -159,7 +159,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  			sscanf(ptr, "%d", &cpu->x86);
>  			continue;
>  		}
> -		if (!strncmp(buffer, "model name", 10)) {
> +		if (!cpu->model_name && !strncmp(buffer, "model name", 10)) {
>  			cpu->model_name = strdup(ptr);
>  			continue;
>  		}
> @@ -171,7 +171,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
>  			sscanf(ptr, "%d", &cpu->stepping);
>  			continue;
>  		}
> -		if (!strncmp(buffer, "flags", 5)) {
> +		if (!cpu->flags && !strncmp(buffer, "flags", 5)) {
>  			cpu->flags = strdup(ptr);
>  			continue;
>  		}


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
index e866d1dc..71e0e877 100644
--- a/src/lib/src/fwts_cpu.c
+++ b/src/lib/src/fwts_cpu.c
@@ -151,7 +151,7 @@  fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
 
 		found = true;
 
-		if (!strncmp(buffer, "vendor_id", 9)) {
+		if (!cpu->vendor_id && !strncmp(buffer, "vendor_id", 9)) {
 			cpu->vendor_id = strdup(ptr);
 			continue;
 		}
@@ -159,7 +159,7 @@  fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
 			sscanf(ptr, "%d", &cpu->x86);
 			continue;
 		}
-		if (!strncmp(buffer, "model name", 10)) {
+		if (!cpu->model_name && !strncmp(buffer, "model name", 10)) {
 			cpu->model_name = strdup(ptr);
 			continue;
 		}
@@ -171,7 +171,7 @@  fwts_cpuinfo_x86 *fwts_cpu_get_info(int which_cpu)
 			sscanf(ptr, "%d", &cpu->stepping);
 			continue;
 		}
-		if (!strncmp(buffer, "flags", 5)) {
+		if (!cpu->flags && !strncmp(buffer, "flags", 5)) {
 			cpu->flags = strdup(ptr);
 			continue;
 		}