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 <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2019-03-14 11:51:16 -07:00 committed by Anas Nashif
commit 000a256bb3
5 changed files with 22 additions and 20 deletions

View file

@ -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, static inline void log_backend_put(const struct log_backend *const backend,
struct log_msg *msg) struct log_msg *msg)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
__ASSERT_NO_MSG(msg); __ASSERT_NO_MSG(msg != NULL);
backend->api->put(backend, msg); backend->api->put(backend, msg);
} }
@ -115,7 +115,7 @@ static inline void log_backend_put_sync_string(
u32_t timestamp, const char *fmt, u32_t timestamp, const char *fmt,
va_list ap) va_list ap)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
if (backend->api->put_sync_string) { if (backend->api->put_sync_string) {
backend->api->put_sync_string(backend, src_level, 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, u32_t timestamp, const char *metadata,
const u8_t *data, u32_t len) const u8_t *data, u32_t len)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
if (backend->api->put_sync_hexdump) { if (backend->api->put_sync_hexdump) {
backend->api->put_sync_hexdump(backend, src_level, timestamp, 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, static inline void log_backend_dropped(const struct log_backend *const backend,
u32_t cnt) u32_t cnt)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
if (backend->api->dropped != NULL) { if (backend->api->dropped != NULL) {
backend->api->dropped(backend, cnt); 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) 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); 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, static inline void log_backend_id_set(const struct log_backend *const backend,
u8_t id) u8_t id)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
backend->cb->id = id; 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) 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; 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, static inline void log_backend_activate(const struct log_backend *const backend,
void *ctx) void *ctx)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
backend->cb->ctx = ctx; backend->cb->ctx = ctx;
backend->cb->active = true; 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( static inline void log_backend_deactivate(
const struct log_backend *const backend) const struct log_backend *const backend)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
backend->cb->active = false; backend->cb->active = false;
} }
@ -263,7 +263,7 @@ static inline void log_backend_deactivate(
static inline bool log_backend_is_active( static inline bool log_backend_is_active(
const struct log_backend *const backend) const struct log_backend *const backend)
{ {
__ASSERT_NO_MSG(backend); __ASSERT_NO_MSG(backend != NULL);
return backend->cb->active; return backend->cb->active;
} }

View file

@ -98,7 +98,7 @@ extern "C" {
* @def LOG_CURRENT_MODULE_ID * @def LOG_CURRENT_MODULE_ID
* @brief Macro for getting ID of current module. * @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) log_const_source_id(__log_current_const_data) : 0)
/** /**
@ -200,7 +200,7 @@ extern "C" {
(IS_ENABLED(CONFIG_LOG) && \ (IS_ENABLED(CONFIG_LOG) && \
(Z_LOG_LEVEL_CHECK(_level, CONFIG_LOG_OVERRIDE_LEVEL, LOG_LEVEL_NONE) \ (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 <= __log_level) && \
(_level <= CONFIG_LOG_MAX_LEVEL) \ (_level <= CONFIG_LOG_MAX_LEVEL) \
) \ ) \

View file

@ -496,7 +496,7 @@ static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node,
} else { } else {
sys_dnode_t *pos = sys_dlist_peek_head(list); 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); pos = sys_dlist_peek_next(list, pos);
} }
if (pos != NULL) { if (pos != NULL) {

View file

@ -72,7 +72,8 @@
static inline sys_ ## __nname ## _t * \ static inline sys_ ## __nname ## _t * \
sys_ ## __lname ## _peek_next(sys_ ## __nname ## _t *node) \ 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; \ NULL; \
} }
@ -85,7 +86,7 @@
sys_ ## __lname ## _peek_head(list)); \ sys_ ## __lname ## _peek_head(list)); \
z_ ## __lname ## _head_set(list, node); \ z_ ## __lname ## _head_set(list, node); \
\ \
if (!sys_ ## __lname ## _peek_tail(list)) { \ if (sys_ ## __lname ## _peek_tail(list) == NULL) { \
z_ ## __lname ## _tail_set(list, \ z_ ## __lname ## _tail_set(list, \
sys_ ## __lname ## _peek_head(list)); \ sys_ ## __lname ## _peek_head(list)); \
} \ } \
@ -98,7 +99,7 @@
{ \ { \
z_ ## __nname ## _next_set(node, NULL); \ 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 ## _tail_set(list, node); \
z_ ## __lname ## _head_set(list, node); \ z_ ## __lname ## _head_set(list, node); \
} else { \ } else { \
@ -114,7 +115,7 @@
sys_ ## __lname ## _append_list(sys_ ## __lname ## _t *list, \ sys_ ## __lname ## _append_list(sys_ ## __lname ## _t *list, \
void *head, void *tail) \ void *head, void *tail) \
{ \ { \
if (!sys_ ## __lname ## _peek_tail(list)) { \ if (sys_ ## __lname ## _peek_tail(list) == NULL) { \
z_ ## __lname ## _head_set(list, \ z_ ## __lname ## _head_set(list, \
(sys_ ## __nname ## _t *)head); \ (sys_ ## __nname ## _t *)head); \
} else { \ } else { \
@ -147,7 +148,7 @@
{ \ { \
if (prev == NULL) { \ if (prev == NULL) { \
sys_ ## __lname ## _prepend(list, node); \ 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); \ sys_ ## __lname ## _append(list, node); \
} else { \ } else { \
z_ ## __nname ## _next_set(node, \ z_ ## __nname ## _next_set(node, \

View file

@ -13,6 +13,7 @@
#define ZEPHYR_INCLUDE_MISC_STACK_H_ #define ZEPHYR_INCLUDE_MISC_STACK_H_
#include <logging/log.h> #include <logging/log.h>
#include <stdbool.h>
static inline size_t stack_unused_space_get(const char *stack, size_t size) 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, \ stack_analyze(name, \
K_THREAD_STACK_BUFFER(sym), \ K_THREAD_STACK_BUFFER(sym), \
K_THREAD_STACK_SIZEOF(sym)); \ K_THREAD_STACK_SIZEOF(sym)); \
} while (0) } while (false)
#endif /* ZEPHYR_INCLUDE_MISC_STACK_H_ */ #endif /* ZEPHYR_INCLUDE_MISC_STACK_H_ */