Remove parentheses from assert argument evaluation

This helps with catching errors like `assert(x = y)`.
This commit is contained in:
borysp
2020-12-31 00:38:40 +01:00
parent 1df560ee2e
commit ae9b49ecb1
2 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ void shim_xstate_restore(const void* xstate_extended) {
assert(fpx_sw->magic1 == SHIM_FP_XSTATE_MAGIC1);
assert(fpx_sw->extended_size == g_shim_xsave_size + SHIM_FP_XSTATE_MAGIC2_SIZE);
assert(fpx_sw->xfeatures == g_shim_xsave_features);
assert(fpx_sw->xstate_size = g_shim_xsave_size);
assert(fpx_sw->xstate_size == g_shim_xsave_size);
assert(*((__typeof__(SHIM_FP_XSTATE_MAGIC2)*)bytes_after_xstate) == SHIM_FP_XSTATE_MAGIC2);
__UNUSED(bytes_after_xstate);
+9 -7
View File
@@ -21,13 +21,15 @@ noreturn void __abort(void);
* build system.
*/
#ifdef DEBUG
#define assert(expr) \
({ \
(!(expr)) ? ({ \
warn("assert failed " __FILE__ ":%d %s\n", __LINE__, #expr); \
__abort(); \
}) \
: (void)0; \
/* This `if` is weird intentionally - not to have parentheses around `expr` to catch `assert(x = y)`
* errors. */
#define assert(expr) \
({ \
if (expr) {} else { \
warn("assert failed " __FILE__ ":%d %s\n", __LINE__, #expr); \
__abort(); \
} \
(void)0; \
})
#else
#define assert(expr) ((void)0)