]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add IGNORE() macro to let us avoid some identical branch annotations (#4948)
authorJames Jones <jejones3141@gmail.com>
Thu, 30 Mar 2023 14:53:05 +0000 (09:53 -0500)
committerGitHub <noreply@github.com>
Thu, 30 Mar 2023 14:53:05 +0000 (08:53 -0600)
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.

src/include/build.h
src/lib/tls/session.c

index 0cb8fce5a7279aa6d2e9d05c00c8d4c1684df3b3..ec00bbc481807132a59ee0540245d6406e5b6328 100644 (file)
@@ -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)
index 222a4731d708babfe1cfa1f539373e2a87014767..5b5e016ae6eff96ff329c4323ebd173004452da6 100644 (file)
@@ -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: