Skip to content

Commit 2476b4c

Browse files
committed
Update the ND_ICHECKMSG_U and ND_ICHECKMSG_ZU macro definitions
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.
1 parent dd2c53b commit 2476b4c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

netdissect.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,12 @@ NORETURN void nd_trunc_longjmp(netdissect_options *ndo);
410410
* a custom message, format %u
411411
*/
412412
#define ND_ICHECKMSG_U(message, expression_1, operator, expression_2) \
413+
do { \
413414
if ((expression_1) operator (expression_2)) { \
414415
ND_PRINT(" [%s %u %s %u]", (message), (expression_1), (#operator), (expression_2)); \
415416
goto invalid; \
416-
}
417+
} \
418+
} while (0)
417419

418420
/*
419421
* Check (expression_1 operator expression_2) for invalid packet with
@@ -427,10 +429,12 @@ ND_ICHECKMSG_U((#expression_1), (expression_1), operator, (expression_2))
427429
* a custom message, format %zu
428430
*/
429431
#define ND_ICHECKMSG_ZU(message, expression_1, operator, expression_2) \
432+
do { \
430433
if ((expression_1) operator (expression_2)) { \
431434
ND_PRINT(" [%s %u %s %zu]", (message), (expression_1), (#operator), (expression_2)); \
432435
goto invalid; \
433-
}
436+
} \
437+
} while (0)
434438

435439
/*
436440
* Check (expression_1 operator expression_2) for invalid packet with

0 commit comments

Comments
 (0)