From: James Jones Date: Thu, 30 Mar 2023 14:53:05 +0000 (-0500) Subject: Add IGNORE() macro to let us avoid some identical branch annotations (#4948) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a6178d3ac0a304dfa1237e1fe07b35e3cc98ad9;p=thirdparty%2Ffreeradius-server.git Add IGNORE() macro to let us avoid some identical branch annotations (#4948) If the unused-return warning is set, gcc will complain even in the presence of an explicit cast to void. This lets us avoid that warning in an error handling case that would otherwise be written if (cleanup() < 0) goto error; goto error; about which Coverity complains. --- diff --git a/src/include/build.h b/src/include/build.h index 0cb8fce5a7..ec00bbc481 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -452,3 +452,20 @@ do { \ * For closing macros which open a code block e.g. fr_rb_inorder_foreach */ #define endforeach } + +/* Explicitly evaluate and ignore an expression + * + * Why this macro? + * 1. gcc will warn about unused return values, even with the traditional cast to void. + * 2. There are cases in which an error case wants to clean up, but the function to + * clean up itself returns a status. In this context you don't care, but then you + * have the Scylla of unused return value and the Charybdis of Coverity complaining + * about an if that doesn't affect control flow. The following evaluates _expr and + * stores it in a variable marked as unused + * @param _expr The expression to be evaluated and ignored + * @param _type The type of the expression + */ +#define IGNORE(_expr, _type) \ + do { \ + _type ignored UNUSED = (_expr); \ + } while (0) diff --git a/src/lib/tls/session.c b/src/lib/tls/session.c index 222a4731d7..5b5e016ae6 100644 --- a/src/lib/tls/session.c +++ b/src/lib/tls/session.c @@ -1447,8 +1447,7 @@ DIAG_ON(DIAG_UNKNOWN_PRAGMAS) ua = fr_tls_cache_pending_push(request, tls_session); switch (ua) { case UNLANG_ACTION_FAIL: - /* coverity[identical_branches] */ - if (unlang_function_clear(request) < 0) goto error; + IGNORE(unlang_function_clear(request), int); goto error; case UNLANG_ACTION_PUSHED_CHILD: @@ -1465,8 +1464,7 @@ DIAG_ON(DIAG_UNKNOWN_PRAGMAS) ua = fr_tls_verify_cert_pending_push(request, tls_session); switch (ua) { case UNLANG_ACTION_FAIL: - /* coverity[identical_branches] */ - if (unlang_function_clear(request) < 0) goto error; + IGNORE(unlang_function_clear(request), int); goto error; default: