Skip to content

Commit b0564df

Browse files
nandojvecarlescufi
authored andcommitted
zephyr/ztest_assert.h: Fix implicit to bool conversion
The current zassert macro uses implicit conversion to boolean which has implication on analysis tools like clang-tidy-14. This add an aditional step to create a boolean value for the evaluation instead use the string direct which allows run analysis tool without this warning/error. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 09cad20 commit b0564df

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

subsys/testsuite/ztest/include/zephyr/ztest_assert.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
132132
*/
133133
#define zassert(cond, default_msg, msg, ...) \
134134
do { \
135-
bool _ret = z_zassert(cond, msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
136-
__LINE__, __func__, msg ? msg : "", ##__VA_ARGS__); \
135+
bool _msg = (msg != NULL); \
136+
bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
137+
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
138+
(void)_msg; \
137139
if (!_ret) { \
138140
/* If kernel but without multithreading return. */ \
139141
COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
@@ -161,8 +163,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
161163
*/
162164
#define zassume(cond, default_msg, msg, ...) \
163165
do { \
164-
bool _ret = z_zassume(cond, msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
165-
__LINE__, __func__, msg ? msg : "", ##__VA_ARGS__); \
166+
bool _msg = (msg != NULL); \
167+
bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
168+
__LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
169+
(void)_msg; \
166170
if (!_ret) { \
167171
/* If kernel but without multithreading return. */ \
168172
COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \

0 commit comments

Comments
 (0)