Skip to content

Commit 6fa6243

Browse files
committed
Update the ND_TCHECK_LEN macro definitions
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 ^
1 parent 2476b4c commit 6fa6243

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

netdissect.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,15 @@ NORETURN void nd_trunc_longjmp(netdissect_options *ndo);
386386

387387
/* Bail out if "l" bytes from "p" were not captured */
388388
#ifdef ND_LONGJMP_FROM_TCHECK
389-
#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo)
389+
#define ND_TCHECK_LEN(p, l) \
390+
do { \
391+
if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo); \
392+
} while (0)
390393
#else
391-
#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
394+
#define ND_TCHECK_LEN(p, l) \
395+
do { \
396+
if (!ND_TTEST_LEN(p, l)) goto trunc; \
397+
} while (0)
392398
#endif
393399

394400
/* Bail out if "*(p)" was not captured */

0 commit comments

Comments
 (0)