From: Stefan Metzmacher Date: Tue, 10 Sep 2019 08:55:15 +0000 (+0200) Subject: lib/torture: protect torture_assert[_goto]() with a do { } while(0) block X-Git-Tag: talloc-2.3.1~941 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8270b8c0b2141e3db1cba16b72d152686efe824f;p=thirdparty%2Fsamba.git lib/torture: protect torture_assert[_goto]() with a do { } while(0) block This hopefully fixes a lot of coverity defects like: Control flow issues (DEADCODE) Execution cannot reach this statement: ";". Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/lib/torture/torture.h b/lib/torture/torture.h index 3507740967c..dbc711e25a1 100644 --- a/lib/torture/torture.h +++ b/lib/torture/torture.h @@ -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; \