]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Update the ND_ICHECKMSG_U and ND_ICHECKMSG_ZU macro definitions
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 15 Oct 2024 10:02:37 +0000 (12:02 +0200)
committerfxlb <[email protected]>
Tue, 15 Oct 2024 18:32:51 +0000 (18:32 +0000)
Avoid errors such as in the following case:

        if (...)
                ND_ICHECKMSG_U(...);
else

source.c:X:9: error: 'else' without a previous 'if'
    X |         else
      |         ^~~~

with gcc, or "error: expected expression" with clang.

This avoids the need to use explicit braces (dangling else).

Same for ND_ICHECK_U, ND_ICHECKMSG_ZU and ND_ICHECK_ZU.

netdissect.h

index fde2ea4856b80c2a7b1262315b274564b8be1d36..62383e651a585e73319b04e0a5620634889c10e1 100644 (file)
@@ -410,10 +410,12 @@ NORETURN void nd_trunc_longjmp(netdissect_options *ndo);
  * a custom message, format %u
  */
 #define ND_ICHECKMSG_U(message, expression_1, operator, expression_2) \
+do { \
 if ((expression_1) operator (expression_2)) { \
 ND_PRINT(" [%s %u %s %u]", (message), (expression_1), (#operator), (expression_2)); \
 goto invalid; \
-}
+} \
+} while (0)
 
 /*
  * Check (expression_1 operator expression_2) for invalid packet with
@@ -427,10 +429,12 @@ ND_ICHECKMSG_U((#expression_1), (expression_1), operator, (expression_2))
  * a custom message, format %zu
  */
 #define ND_ICHECKMSG_ZU(message, expression_1, operator, expression_2) \
+do { \
 if ((expression_1) operator (expression_2)) { \
 ND_PRINT(" [%s %u %s %zu]", (message), (expression_1), (#operator), (expression_2)); \
 goto invalid; \
-}
+} \
+} while (0)
 
 /*
  * Check (expression_1 operator expression_2) for invalid packet with