Permalink
Browse files

Put assert check into macro for static analyzers

This way an analyzer will see it aborts when the
expression is false; especially the ccc-analyzer (clang)
generated many false positives otherwise.
  • Loading branch information...
1 parent 24dd542 commit b82d54260d20bb3511b7a3cb33bbf7114502c23a @stbuehler stbuehler committed Jun 1, 2012
Showing with 8 additions and 10 deletions.
  1. +8 −10 util/Assert.h
View
@@ -26,14 +26,6 @@
#define Assert_GLUE(x, y) x ## y
#define Assert_STRING(x) #x
-static inline void Assert_internal(const char* expr, int isTrue, const char* file, int line)
-{
- if (!isTrue) {
- fprintf(stderr, "%s:%d Assertion failed: %s", file, line, expr);
- abort();
- }
-}
-
/**
* Assert_compileTime()
*
@@ -45,8 +37,14 @@ static inline void Assert_internal(const char* expr, int isTrue, const char* fil
/** Runtime assertion which is always applied. */
-#define Assert_always(expr) \
- Assert_internal(Assert_STRING(expr), (expr) ? 1 : 0, __FILE__, __LINE__)
+#define Assert_always(expr) do { \
+ if (!(expr)) { \
+ fprintf(stderr, "%s:%d Assertion failed: %s\n", \
+ __FILE__, __LINE__, Assert_STRING(expr)); \
+ abort(); \
+ } \
+ } while (0)
+/* CHECKFILES_IGNORE a ; is expected after the while(0) but it will be supplied by the caller */
// Turn off assertions when the code is more stable.
#define Assert_true(expr) Assert_always(expr)

0 comments on commit b82d542

Please sign in to comment.