]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Update the ND_TCHECK_LEN macro definitions
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 15 Oct 2024 19:08:57 +0000 (21:08 +0200)
committerfxlb <[email protected]>
Wed, 16 Oct 2024 19:12:16 +0000 (19:12 +0000)
Avoid warnings such as in the following case:

        if (...)
                ND_TCHECK_LEN(...);
        else

With gcc:
source.c:X:12: warning: suggest explicit braces to avoid ambiguous
  'else' [-Wdangling-else]
    X |         if (...)
      |            ^

With clang:
source.c:Y:2: warning: add explicit braces to avoid dangling else
  [-Wdangling-else]
        else
        ^

netdissect.h

index 62383e651a585e73319b04e0a5620634889c10e1..2bd4cfd747e383f19ed05ca86c2a0b0a06afa2a3 100644 (file)
@@ -386,9 +386,15 @@ NORETURN void nd_trunc_longjmp(netdissect_options *ndo);
 
 /* Bail out if "l" bytes from "p" were not captured */
 #ifdef ND_LONGJMP_FROM_TCHECK
-#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo)
+#define ND_TCHECK_LEN(p, l) \
+do { \
+if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo); \
+} while (0)
 #else
-#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
+#define ND_TCHECK_LEN(p, l) \
+do { \
+if (!ND_TTEST_LEN(p, l)) goto trunc; \
+} while (0)
 #endif
 
 /* Bail out if "*(p)" was not captured */