From 604c4bbea3d1cfab7e6af3f9ebd3a1281a9c1d1e Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 17 Mar 2015 19:17:51 +0300 Subject: [PATCH] Fix oops() to not have UB. Writing to NULL is undefined behavior and it is legal for the compiler to simply remove it; clang will do so. abort() or __builtin_trap() would produce the desirable result. abort() is used as it is more portable. --- src/solvespace.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/solvespace.h b/src/solvespace.h index 60889b1..7182225 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -44,8 +44,13 @@ #endif // Debugging functions +#ifdef NDEBUG #define oops() do { dbp("oops at line %d, file %s\n", __LINE__, __FILE__); \ - if(0) *(char *)0 = 1; exit(-1); } while(0) + exit(-1); } while(0) +#else +#define oops() do { dbp("oops at line %d, file %s\n", __LINE__, __FILE__); \ + abort(); } while(0) +#endif #ifndef min # define min(x, y) ((x) < (y) ? (x) : (y))