[PATCH] lib: fwts_log: re-work to clean up va_arg scoping
Colin King
colin.king at canonical.com
Wed Aug 5 07:47:43 UTC 2015
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;
--
2.5.0
More information about the fwts-devel
mailing list