basic: fix ASSERT_SIDE_EFFECT Coverity report in assert_se()
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 21 Sep 2019 15:48:50 +0000 (17:48 +0200)
committerChris Down <chris@chrisdown.name>
Wed, 2 Oct 2019 09:43:47 +0000 (10:43 +0100)
src/basic/macro.h

index 336cb3a..18e5085 100644 (file)
@@ -307,17 +307,18 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
 
 extern void __coverity_panic__(void);
 
-static inline int __coverity_check__(int condition) {
+static inline void __coverity_check__(int condition) {
+        if (!condition)
+                __coverity_panic__();
+}
+
+static inline int __coverity_check_and_return__(int condition) {
         return condition;
 }
 
-#define assert_message_se(expr, message)                                \
-        do {                                                            \
-                if (__coverity_check__(!(expr)))                        \
-                        __coverity_panic__();                           \
-        } while (false)
+#define assert_message_se(expr, message) __coverity_check__(!!(expr))
 
-#define assert_log(expr, message) __coverity_check__(!!(expr))
+#define assert_log(expr, message) __coverity_check_and_return__(!!(expr))
 
 #else  /* ! __COVERITY__ */