Prevent assignments in assertions
Using the else branch instead of explicitly negating the assertion makes sure the compiler catches assignments in assertion expressions.
This commit is contained in:
@ -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__, \
|
||||
|
Reference in New Issue
Block a user