ACK: [PATCH] lib: acpica: explicitly set buffer to NULL to remove cppcheck warning

Alex Hung alex.hung at canonical.com
Thu May 21 23:07:23 UTC 2015


On 05/15/2015 03:36 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> cppcheck isn't quite so smart as CoverityScan so it continues to complain
> about a potential free issue as a false positive.  I've taken the liberty
> to explicity set buffer to NULL to make the code clearer and this helps
> cppcheck to understand the flow of control better.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/acpica/fwts_acpica.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
> index 4a6baf6..9bfd0ae 100644
> --- a/src/acpica/fwts_acpica.c
> +++ b/src/acpica/fwts_acpica.c
> @@ -452,8 +452,10 @@ void fwts_acpica_vprintf(const char *fmt, va_list args)
>  		buffer = malloc(buffer_len);
>  		if (buffer)
>  			strcpy(buffer, tmp);
> -		else
> +		else {
> +			buffer = NULL;
>  			buffer_len = 0;
> +		}
>  	} else {
>  		char *new_buf;
>  
> @@ -464,11 +466,12 @@ void fwts_acpica_vprintf(const char *fmt, va_list args)
>  			strcat(buffer, tmp);
>  		} else {
>  			free(buffer);
> +			buffer = NULL;
>  			buffer_len = 0;
>  		}
>  	}
>  
> -	if (buffer_len && index(buffer, '\n') != NULL) {
> +	if (buffer && index(buffer, '\n') != NULL) {
>  		fwts_log_info(fwts_acpica_fw, "%s", buffer);
>  		free(buffer);
>  		buffer_len = 0;
> 


Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list