log: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type. MISRA-C rule 14.4 Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
6d50df212f
commit
f342019986
8 changed files with 29 additions and 28 deletions
|
@ -107,7 +107,7 @@ static inline void log_backend_dropped(const struct log_backend *const backend,
|
||||||
{
|
{
|
||||||
__ASSERT_NO_MSG(backend);
|
__ASSERT_NO_MSG(backend);
|
||||||
|
|
||||||
if (backend->api->dropped) {
|
if (backend->api->dropped != NULL) {
|
||||||
backend->api->dropped(backend, cnt);
|
backend->api->dropped(backend, cnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,12 +60,12 @@ static int line_out(u8_t *data, size_t length, void *output_ctx)
|
||||||
int ret = -ENOMEM;
|
int ret = -ENOMEM;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
|
||||||
if (!ctx) {
|
if (ctx == NULL) {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(ctx, K_NO_WAIT);
|
pkt = net_pkt_get_tx(ctx, K_NO_WAIT);
|
||||||
if (!pkt) {
|
if (pkt == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ static int line_out(u8_t *data, size_t length, void *output_ctx)
|
||||||
DBG(data);
|
DBG(data);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (ret < 0 && pkt) {
|
if (ret < 0 && (pkt != NULL)) {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ static int do_net_init(void)
|
||||||
local_addr6.sin6_port = 0;
|
local_addr6.sin6_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!local_addr) {
|
if (local_addr == NULL) {
|
||||||
DBG("Server address unknown\n");
|
DBG("Server address unknown\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ static void init_net(void)
|
||||||
ret = net_ipaddr_parse(CONFIG_LOG_BACKEND_NET_SERVER,
|
ret = net_ipaddr_parse(CONFIG_LOG_BACKEND_NET_SERVER,
|
||||||
sizeof(CONFIG_LOG_BACKEND_NET_SERVER) - 1,
|
sizeof(CONFIG_LOG_BACKEND_NET_SERVER) - 1,
|
||||||
&server_addr);
|
&server_addr);
|
||||||
if (!ret) {
|
if (ret == 0) {
|
||||||
LOG_ERR("Cannot configure syslog server address");
|
LOG_ERR("Cannot configure syslog server address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ static int line_out_drop_mode(void)
|
||||||
line_buf, line_pos - line_buf + 1);
|
line_buf, line_pos - line_buf + 1);
|
||||||
RTT_UNLOCK();
|
RTT_UNLOCK();
|
||||||
|
|
||||||
if (!ret) {
|
if (ret == 0) {
|
||||||
drop_cnt++;
|
drop_cnt++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ static int shell_backend_cmd_execute(const struct shell *shell,
|
||||||
char const *name = argv[-1];
|
char const *name = argv[-1];
|
||||||
const struct log_backend *backend = backend_find(name);
|
const struct log_backend *backend = backend_find(name);
|
||||||
|
|
||||||
if (backend) {
|
if (backend != NULL) {
|
||||||
func(shell, backend, argc, argv);
|
func(shell, backend, argc, argv);
|
||||||
} else {
|
} else {
|
||||||
shell_error(shell, "Invalid backend: %s", name);
|
shell_error(shell, "Invalid backend: %s", name);
|
||||||
|
|
|
@ -168,7 +168,7 @@ int log_printk(const char *fmt, va_list ap)
|
||||||
sizeof(formatted_str) : length;
|
sizeof(formatted_str) : length;
|
||||||
|
|
||||||
msg = log_msg_hexdump_create(NULL, formatted_str, length);
|
msg = log_msg_hexdump_create(NULL, formatted_str, length);
|
||||||
if (!msg) {
|
if (msg == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ void log_init(void)
|
||||||
assert(log_backend_count_get() < LOG_FILTERS_NUM_OF_SLOTS);
|
assert(log_backend_count_get() < LOG_FILTERS_NUM_OF_SLOTS);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (atomic_inc(&initialized)) {
|
if (atomic_inc(&initialized) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ void log_init(void)
|
||||||
const struct log_backend *backend = log_backend_get(i);
|
const struct log_backend *backend = log_backend_get(i);
|
||||||
|
|
||||||
if (backend->autostart) {
|
if (backend->autostart) {
|
||||||
if (backend->api->init) {
|
if (backend->api->init != NULL) {
|
||||||
backend->api->init();
|
backend->api->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ char *log_strdup(const char *str)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = k_mem_slab_alloc(&log_strdup_pool, (void **)&dup, K_NO_WAIT);
|
err = k_mem_slab_alloc(&log_strdup_pool, (void **)&dup, K_NO_WAIT);
|
||||||
if (err) {
|
if (err != 0) {
|
||||||
/* failed to allocate */
|
/* failed to allocate */
|
||||||
return (char *)log_strdup_fail_msg;
|
return (char *)log_strdup_fail_msg;
|
||||||
}
|
}
|
||||||
|
@ -588,7 +588,7 @@ static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3)
|
||||||
log_init();
|
log_init();
|
||||||
thread_set(k_current_get());
|
thread_set(k_current_get());
|
||||||
|
|
||||||
while (1) {
|
while (true) {
|
||||||
if (log_process(false) == false) {
|
if (log_process(false) == false) {
|
||||||
k_sleep(CONFIG_LOG_PROCESS_THREAD_SLEEP_MS);
|
k_sleep(CONFIG_LOG_PROCESS_THREAD_SLEEP_MS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ static struct log_msg *msg_alloc(u32_t nargs)
|
||||||
struct log_msg *msg = _log_msg_std_alloc();
|
struct log_msg *msg = _log_msg_std_alloc();
|
||||||
int n = (int)nargs;
|
int n = (int)nargs;
|
||||||
|
|
||||||
if (!msg || nargs <= LOG_MSG_NARGS_SINGLE_CHUNK) {
|
if ((msg == NULL) || nargs <= LOG_MSG_NARGS_SINGLE_CHUNK) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ static struct log_msg *msg_alloc(u32_t nargs)
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
cont = (struct log_msg_cont *)log_msg_chunk_alloc();
|
cont = (struct log_msg_cont *)log_msg_chunk_alloc();
|
||||||
|
|
||||||
if (!cont) {
|
if (cont == NULL) {
|
||||||
msg_free(msg);
|
msg_free(msg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ static void copy_args_to_msg(struct log_msg *msg, u32_t *args, u32_t nargs)
|
||||||
nargs = 0U;
|
nargs = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nargs) {
|
while (nargs != 0) {
|
||||||
u32_t cpy_args = min(nargs, ARGS_CONT_MSG);
|
u32_t cpy_args = min(nargs, ARGS_CONT_MSG);
|
||||||
|
|
||||||
(void)memcpy(cont->payload.args, args,
|
(void)memcpy(cont->payload.args, args,
|
||||||
|
@ -213,7 +213,7 @@ struct log_msg *log_msg_create_n(const char *str, u32_t *args, u32_t nargs)
|
||||||
|
|
||||||
msg = msg_alloc(nargs);
|
msg = msg_alloc(nargs);
|
||||||
|
|
||||||
if (msg) {
|
if (msg != NULL) {
|
||||||
msg->str = str;
|
msg->str = str;
|
||||||
msg->hdr.params.std.nargs = nargs;
|
msg->hdr.params.std.nargs = nargs;
|
||||||
copy_args_to_msg(msg, args, nargs);
|
copy_args_to_msg(msg, args, nargs);
|
||||||
|
@ -236,7 +236,7 @@ struct log_msg *log_msg_hexdump_create(const char *str,
|
||||||
LOG_MSG_HEXDUMP_MAX_LENGTH : length;
|
LOG_MSG_HEXDUMP_MAX_LENGTH : length;
|
||||||
|
|
||||||
msg = (struct log_msg *)log_msg_chunk_alloc();
|
msg = (struct log_msg *)log_msg_chunk_alloc();
|
||||||
if (!msg) {
|
if (msg == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ struct log_msg *log_msg_hexdump_create(const char *str,
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
cont = (struct log_msg_cont *)log_msg_chunk_alloc();
|
cont = (struct log_msg_cont *)log_msg_chunk_alloc();
|
||||||
if (!cont) {
|
if (cont == NULL) {
|
||||||
msg_free(msg);
|
msg_free(msg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define LOG_COLOR_CODE_DEFAULT "\x1B[0m"
|
#define LOG_COLOR_CODE_DEFAULT "\x1B[0m"
|
||||||
#define LOG_COLOR_CODE_RED "\x1B[1;31m"
|
#define LOG_COLOR_CODE_RED "\x1B[1;31m"
|
||||||
|
@ -132,7 +133,7 @@ static void buffer_write(log_output_func_t outf, u8_t *buf, size_t len,
|
||||||
processed = outf(buf, len, ctx);
|
processed = outf(buf, len, ctx);
|
||||||
len -= processed;
|
len -= processed;
|
||||||
buf += processed;
|
buf += processed;
|
||||||
} while (len);
|
} while (len != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_output_flush(const struct log_output *log_output)
|
void log_output_flush(const struct log_output *log_output)
|
||||||
|
@ -157,7 +158,7 @@ static int timestamp_print(struct log_msg *msg,
|
||||||
|
|
||||||
if (!format) {
|
if (!format) {
|
||||||
length = print_formatted(log_output, "[%08lu] ", timestamp);
|
length = print_formatted(log_output, "[%08lu] ", timestamp);
|
||||||
} else if (freq) {
|
} else if (freq != 0) {
|
||||||
u32_t remainder;
|
u32_t remainder;
|
||||||
u32_t seconds;
|
u32_t seconds;
|
||||||
u32_t hours;
|
u32_t hours;
|
||||||
|
@ -267,11 +268,11 @@ static void newline_print(const struct log_output *ctx, u32_t flags)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & LOG_OUTPUT_FLAG_CRLF_NONE) {
|
if ((flags & LOG_OUTPUT_FLAG_CRLF_NONE) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & LOG_OUTPUT_FLAG_CRLF_LFONLY) {
|
if ((flags & LOG_OUTPUT_FLAG_CRLF_LFONLY) != 0) {
|
||||||
print_formatted(ctx, "\n");
|
print_formatted(ctx, "\n");
|
||||||
} else {
|
} else {
|
||||||
print_formatted(ctx, "\r\n");
|
print_formatted(ctx, "\r\n");
|
||||||
|
@ -427,7 +428,7 @@ static void hexdump_print(struct log_msg *msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += length;
|
offset += length;
|
||||||
} while (1);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raw_string_print(struct log_msg *msg,
|
static void raw_string_print(struct log_msg *msg,
|
||||||
|
@ -445,7 +446,7 @@ static void raw_string_print(struct log_msg *msg,
|
||||||
log_msg_hexdump_data_get(msg, log_output->buf, &length, offset);
|
log_msg_hexdump_data_get(msg, log_output->buf, &length, offset);
|
||||||
log_output->control_block->offset = length;
|
log_output->control_block->offset = length;
|
||||||
|
|
||||||
if (length) {
|
if (length != 0) {
|
||||||
eol = (log_output->buf[length - 1] == '\n');
|
eol = (log_output->buf[length - 1] == '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,12 +70,12 @@ static void syslog_hook_net(const char *fmt, ...)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(ctx, K_NO_WAIT);
|
pkt = net_pkt_get_tx(ctx, K_NO_WAIT);
|
||||||
if (!pkt) {
|
if (pkt == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_pkt_get_data(ctx, K_NO_WAIT);
|
frag = net_pkt_get_data(ctx, K_NO_WAIT);
|
||||||
if (!frag) {
|
if (frag == NULL) {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ void syslog_net_hook_install(void)
|
||||||
ret = net_ipaddr_parse(CONFIG_SYS_LOG_BACKEND_NET_SERVER,
|
ret = net_ipaddr_parse(CONFIG_SYS_LOG_BACKEND_NET_SERVER,
|
||||||
sizeof(CONFIG_SYS_LOG_BACKEND_NET_SERVER) - 1,
|
sizeof(CONFIG_SYS_LOG_BACKEND_NET_SERVER) - 1,
|
||||||
&server_addr);
|
&server_addr);
|
||||||
if (!ret) {
|
if (ret == 0) {
|
||||||
SYS_LOG_ERR("Cannot configure syslog server address");
|
SYS_LOG_ERR("Cannot configure syslog server address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue