[PATCH] lib: fwts_log: add LOG_NO_FIELD and use this to indicate an unfound field
Colin King
colin.king at canonical.com
Tue Apr 18 22:08:53 UTC 2017
From: Colin Ian King <colin.king at canonical.com>
Rather than implicitly using a non-enum fwts_log_field value zero
to indicate an unfound field instead use a new explicitly defined
LOG_NO_FIELD enum value to indicate this. This cleans up a couple
of static analysis warnings of the form:
"The variable 'field' is of enum type. It is odd that it is used as a
variable of a Boolean-type."
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/include/fwts_log.h | 1 +
src/lib/src/fwts_log.c | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/lib/include/fwts_log.h b/src/lib/include/fwts_log.h
index 3c7dd4d3..028ba36c 100644
--- a/src/lib/include/fwts_log.h
+++ b/src/lib/include/fwts_log.h
@@ -30,6 +30,7 @@
#define LOG_MAX_BUF_SIZE (4096) /* Max output per log line */
typedef enum {
+ LOG_NO_FIELD = 0x00000000,
LOG_RESULT = 0x00000001,
LOG_ERROR = 0x00000002,
LOG_WARNING = 0x00000004,
diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
index d6c599d5..13d5f6ca 100644
--- a/src/lib/src/fwts_log.c
+++ b/src/lib/src/fwts_log.c
@@ -247,7 +247,7 @@ fwts_log_field fwts_log_str_to_field(const char *text)
for (i = 0; mappings[i].text != NULL; i++)
if (strcmp(mappings[i].text, text) == 0)
return mappings[i].field;
- return 0;
+ return LOG_NO_FIELD;
}
/*
@@ -286,12 +286,12 @@ void fwts_log_set_field_filter(const char *str)
break;
if (*token == '^' || *token == '~') {
field = fwts_log_str_to_field(token+1);
- if (field)
+ if (field != LOG_NO_FIELD)
fwts_log_filter_unset_field(field);
}
else {
field = fwts_log_str_to_field(token);
- if (field)
+ if (field != LOG_NO_FIELD)
fwts_log_filter_set_field(field);
}
}
--
2.11.0
More information about the fwts-devel
mailing list