lib/torture: protect torture_assert[_goto]() with a do { } while(0) block
authorStefan Metzmacher <metze@samba.org>
Tue, 10 Sep 2019 08:55:15 +0000 (10:55 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 10 Sep 2019 17:38:40 +0000 (17:38 +0000)
This hopefully fixes a lot of coverity defects like:

Control flow issues  (DEADCODE)
Execution cannot reach this statement: ";".

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/torture/torture.h

index 3507740967c0094acb659c86f3e9f186848a8954..dbc711e25a139b596881644d3e8194bb3361930e 100644 (file)
@@ -249,18 +249,20 @@ void torture_warning(struct torture_context *test, const char *comment, ...) PRI
 void torture_result(struct torture_context *test,
                        enum torture_result, const char *reason, ...) PRINTF_ATTRIBUTE(3,4);
 
-#define torture_assert(torture_ctx,expr,cmt) \
+#define torture_assert(torture_ctx,expr,cmt) do { \
        if (!(expr)) { \
                torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
                return false; \
-       }
+       } \
+} while(0)
 
-#define torture_assert_goto(torture_ctx,expr,ret,label,cmt) \
+#define torture_assert_goto(torture_ctx,expr,ret,label,cmt) do { \
        if (!(expr)) { \
                torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
                ret = false; \
                goto label; \
-       }
+       } \
+} while(0)
 
 #define torture_assert_werr_equal(torture_ctx, got, expected, cmt) \
        do { WERROR __got = got, __expected = expected; \