From 0350026866be6d180d750297567e55c0e8c2005d Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 18 May 2014 00:56:45 +0200 Subject: [PATCH] WUtil: change 'wassertr(v)' to still perform check even if NDEBUG is set In many places of the code these functions are counting on the "return" effect of these macros to gracefully handle incorrect arguments. So, when debug is not enabled, if it is okay to not display a message it is however not good to completely skip the check and skip the early return. This patch changes the macro to always perform the check and return to avoid crashes, displaying a message only when NDEBUG is not set. Signed-off-by: Christophe CURIS --- WINGs/WINGs/WUtil.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index da74dfc3..01d03684 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -55,21 +55,14 @@ #ifdef NDEBUG -#define wassertr(expr) {} -#define wassertrv(expr, val) {} +#define wassertr(expr) \ + if (!(expr)) { return; } + +#define wassertrv(expr, val) \ + if (!(expr)) { return (val); } #else /* !NDEBUG */ -#ifdef DEBUG - -#include - -#define wassertr(expr) assert(expr) - -#define wassertrv(expr, val) assert(expr) - -#else /* !DEBUG */ - #define wassertr(expr) \ if (!(expr)) { \ wwarning("%s line %i (%s): assertion %s failed",\ @@ -83,7 +76,6 @@ __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\ return (val);\ } -#endif /* !DEBUG */ #endif /* !NDEBUG */