...
When multiple statements are used in a macro, they should be bound together in a loop syntactically, so the macro can appear safely inside if - clauses , or other places that expect a single statement or a statement block.
Noncompliant Code Example
This noncompliant code example contains multiple, unbound statements.
Code Block | ||
---|---|---|
| ||
/* * Swaps two values. * Requires tmp variable to be defined. */ #define SWAP(x, y) \ tmp = x; \ x = y; \ y = tmp |
...
Code Block | ||
---|---|---|
| ||
int x, y, z, tmp; if (z == 0) SWAP( x, y); |
This will expand to:
Code Block | ||
---|---|---|
| ||
int x, y, z, tmp; if (z == 0) tmp = x; x = y; y = tmp; |
...
Risk Assessment
Improperly sealed wrapped statement macros will cause behavior that is can result in unexpected and difficult to diagnose behavior.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
PRE10-C | medium | probable | low | P12 | L1 |
...