ACK: [PATCH] lib: fwts_log: re-work to clean up va_arg scoping

Alex Hung alex.hung at canonical.com
Thu Aug 6 09:17:31 UTC 2015


On 08/05/2015 03:47 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> cppcheck is reporting a style issue:
> [src/lib/src/fwts_log.c:407]:
>   (style) The scope of the variable 'args' can be reduced.
> 
> Re-work the code to fix this and don't do a return without
> a va_end() when vsnprintf returns an error.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_log.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
> index 22dca31..fde6035 100644
> --- a/src/lib/src/fwts_log.c
> +++ b/src/lib/src/fwts_log.c
> @@ -404,15 +404,14 @@ int fwts_log_printf(fwts_log *log,
>  	const char *prefix,
>  	const char *fmt, ...)
>  {
> -	va_list	args;
>  	int ret = 0;
>  
>  	if (!((field & LOG_FIELD_MASK) & fwts_log_filter))
>  		return ret;
>  
>  	if (log && log->magic == LOG_MAGIC) {
> -		fwts_list_link *item;
>  		char buffer[LOG_MAX_BUF_SIZE];
> +		va_list	args;
>  
>  		/*
>  		 * With the possibility of having multiple logs being written
> @@ -423,17 +422,17 @@ int fwts_log_printf(fwts_log *log,
>  		 */
>  		va_start(args, fmt);
>  		ret = vsnprintf(buffer, sizeof(buffer), fmt, args);
> -		if (ret < 0)
> -			return ret;
> +		if (ret >= 0) {
> +			fwts_list_link *item;
>  
> -		fwts_list_foreach(item, &log->log_files) {
> -			fwts_log_file *log_file = fwts_list_data(fwts_log_file *, item);
> +			fwts_list_foreach(item, &log->log_files) {
> +				fwts_log_file *log_file = fwts_list_data(fwts_log_file *, item);
>  
> -			if (log_file->ops && log_file->ops->print)
> -				log_file->ops->print(log_file, field, level,
> -					status, label, prefix, buffer);
> +				if (log_file->ops && log_file->ops->print)
> +					log_file->ops->print(log_file, field, level,
> +						status, label, prefix, buffer);
> +			}
>  		}
> -
>  		va_end(args);
>  	}
>  	return ret;
> 
Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list