From dc244342f8a50b5216c233f70fa11e5a053ee69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 25 Apr 2019 14:45:13 +0300 Subject: [PATCH] Prevent assignments in assertions Using the else branch instead of explicitly negating the assertion makes sure the compiler catches assignments in assertion expressions. --- maxutils/maxbase/include/maxbase/assert.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maxutils/maxbase/include/maxbase/assert.h b/maxutils/maxbase/include/maxbase/assert.h index e37773ef7..ac0391520 100644 --- a/maxutils/maxbase/include/maxbase/assert.h +++ b/maxutils/maxbase/include/maxbase/assert.h @@ -24,7 +24,7 @@ MXB_BEGIN_DECLS #if defined (SS_DEBUG) #define mxb_assert(exp) \ - do {if (!(exp)) { \ + do {if (exp) {} else { \ const char* debug_expr = #exp; /** The MXB_ERROR marco doesn't seem to like stringification * */ \ MXB_ERROR("debug assert at %s:%d failed: %s\n", (char*)__FILE__, __LINE__, debug_expr); \ @@ -32,7 +32,7 @@ MXB_BEGIN_DECLS raise(SIGABRT);}} while (false) #define mxb_assert_message(exp, message) \ - do {if (!(exp)) { \ + do {if (exp) {} else { \ const char* debug_expr = #exp; \ MXB_ERROR("debug assert at %s:%d failed: %s (%s)\n", \ (char*)__FILE__, \