From 000a256bb3ace077b185376703d92be5a7c61568 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 14 Mar 2019 11:51:16 -0700 Subject: [PATCH] include: Make statements evaluate boolean expressions MISRA-C requires that if/while statements have essentially a boolean operand. MISRA-C rule 14.4 Signed-off-by: Flavio Ceolin --- include/logging/log_backend.h | 22 +++++++++++----------- include/logging/log_core.h | 4 ++-- include/misc/dlist.h | 2 +- include/misc/list_gen.h | 11 ++++++----- include/misc/stack.h | 3 ++- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/logging/log_backend.h b/include/logging/log_backend.h index 56664058409..68ec651ea81 100644 --- a/include/logging/log_backend.h +++ b/include/logging/log_backend.h @@ -95,8 +95,8 @@ extern const struct log_backend __log_backends_end[0]; static inline void log_backend_put(const struct log_backend *const backend, struct log_msg *msg) { - __ASSERT_NO_MSG(backend); - __ASSERT_NO_MSG(msg); + __ASSERT_NO_MSG(backend != NULL); + __ASSERT_NO_MSG(msg != NULL); backend->api->put(backend, msg); } @@ -115,7 +115,7 @@ static inline void log_backend_put_sync_string( u32_t timestamp, const char *fmt, va_list ap) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); if (backend->api->put_sync_string) { backend->api->put_sync_string(backend, src_level, @@ -139,7 +139,7 @@ static inline void log_backend_put_sync_hexdump( u32_t timestamp, const char *metadata, const u8_t *data, u32_t len) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); if (backend->api->put_sync_hexdump) { backend->api->put_sync_hexdump(backend, src_level, timestamp, @@ -158,7 +158,7 @@ static inline void log_backend_put_sync_hexdump( static inline void log_backend_dropped(const struct log_backend *const backend, u32_t cnt) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); if (backend->api->dropped != NULL) { backend->api->dropped(backend, cnt); @@ -172,7 +172,7 @@ static inline void log_backend_dropped(const struct log_backend *const backend, */ static inline void log_backend_panic(const struct log_backend *const backend) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); backend->api->panic(backend); } @@ -187,7 +187,7 @@ static inline void log_backend_panic(const struct log_backend *const backend) static inline void log_backend_id_set(const struct log_backend *const backend, u8_t id) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); backend->cb->id = id; } @@ -201,7 +201,7 @@ static inline void log_backend_id_set(const struct log_backend *const backend, */ static inline u8_t log_backend_id_get(const struct log_backend *const backend) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); return backend->cb->id; } @@ -236,7 +236,7 @@ static inline int log_backend_count_get(void) static inline void log_backend_activate(const struct log_backend *const backend, void *ctx) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); backend->cb->ctx = ctx; backend->cb->active = true; } @@ -249,7 +249,7 @@ static inline void log_backend_activate(const struct log_backend *const backend, static inline void log_backend_deactivate( const struct log_backend *const backend) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); backend->cb->active = false; } @@ -263,7 +263,7 @@ static inline void log_backend_deactivate( static inline bool log_backend_is_active( const struct log_backend *const backend) { - __ASSERT_NO_MSG(backend); + __ASSERT_NO_MSG(backend != NULL); return backend->cb->active; } diff --git a/include/logging/log_core.h b/include/logging/log_core.h index 727181b3d89..eb4a86317b6 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -98,7 +98,7 @@ extern "C" { * @def LOG_CURRENT_MODULE_ID * @brief Macro for getting ID of current module. */ -#define LOG_CURRENT_MODULE_ID() (__log_level ? \ +#define LOG_CURRENT_MODULE_ID() (__log_level != 0 ? \ log_const_source_id(__log_current_const_data) : 0) /** @@ -200,7 +200,7 @@ extern "C" { (IS_ENABLED(CONFIG_LOG) && \ (Z_LOG_LEVEL_CHECK(_level, CONFIG_LOG_OVERRIDE_LEVEL, LOG_LEVEL_NONE) \ || \ - (!IS_ENABLED(CONFIG_LOG_OVERRIDE_LEVEL) && \ + ((IS_ENABLED(CONFIG_LOG_OVERRIDE_LEVEL) == false) && \ (_level <= __log_level) && \ (_level <= CONFIG_LOG_MAX_LEVEL) \ ) \ diff --git a/include/misc/dlist.h b/include/misc/dlist.h index e16a70d8dc1..dab55dddf79 100644 --- a/include/misc/dlist.h +++ b/include/misc/dlist.h @@ -496,7 +496,7 @@ static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node, } else { sys_dnode_t *pos = sys_dlist_peek_head(list); - while (pos && !cond(pos, data)) { + while ((pos != NULL) && (cond(pos, data) == 0)) { pos = sys_dlist_peek_next(list, pos); } if (pos != NULL) { diff --git a/include/misc/list_gen.h b/include/misc/list_gen.h index e9cb41598a3..221353b80ae 100644 --- a/include/misc/list_gen.h +++ b/include/misc/list_gen.h @@ -72,7 +72,8 @@ static inline sys_ ## __nname ## _t * \ sys_ ## __lname ## _peek_next(sys_ ## __nname ## _t *node) \ { \ - return node ? sys_ ## __lname ## _peek_next_no_check(node) : \ + return node != NULL ? \ + sys_ ## __lname ## _peek_next_no_check(node) : \ NULL; \ } @@ -85,7 +86,7 @@ sys_ ## __lname ## _peek_head(list)); \ z_ ## __lname ## _head_set(list, node); \ \ - if (!sys_ ## __lname ## _peek_tail(list)) { \ + if (sys_ ## __lname ## _peek_tail(list) == NULL) { \ z_ ## __lname ## _tail_set(list, \ sys_ ## __lname ## _peek_head(list)); \ } \ @@ -98,7 +99,7 @@ { \ z_ ## __nname ## _next_set(node, NULL); \ \ - if (!sys_ ## __lname ## _peek_tail(list)) { \ + if (sys_ ## __lname ## _peek_tail(list) == NULL) { \ z_ ## __lname ## _tail_set(list, node); \ z_ ## __lname ## _head_set(list, node); \ } else { \ @@ -114,7 +115,7 @@ sys_ ## __lname ## _append_list(sys_ ## __lname ## _t *list, \ void *head, void *tail) \ { \ - if (!sys_ ## __lname ## _peek_tail(list)) { \ + if (sys_ ## __lname ## _peek_tail(list) == NULL) { \ z_ ## __lname ## _head_set(list, \ (sys_ ## __nname ## _t *)head); \ } else { \ @@ -147,7 +148,7 @@ { \ if (prev == NULL) { \ sys_ ## __lname ## _prepend(list, node); \ - } else if (!z_ ## __nname ## _next_peek(prev)) { \ + } else if (z_ ## __nname ## _next_peek(prev) == NULL) { \ sys_ ## __lname ## _append(list, node); \ } else { \ z_ ## __nname ## _next_set(node, \ diff --git a/include/misc/stack.h b/include/misc/stack.h index 33453f09cbc..84f521117bf 100644 --- a/include/misc/stack.h +++ b/include/misc/stack.h @@ -13,6 +13,7 @@ #define ZEPHYR_INCLUDE_MISC_STACK_H_ #include +#include static inline size_t stack_unused_space_get(const char *stack, size_t size) { @@ -86,6 +87,6 @@ static inline void stack_analyze(const char *name, const char *stack, stack_analyze(name, \ K_THREAD_STACK_BUFFER(sym), \ K_THREAD_STACK_SIZEOF(sym)); \ - } while (0) + } while (false) #endif /* ZEPHYR_INCLUDE_MISC_STACK_H_ */