Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#ffcccc
/* 
 * Swaps two values.
 * Requires tmp variable to be defined. 
 */
#define SWAP(x, y) \
  tmp = x; \
  x = y; \
  y = tmp

...

Code Block
bgColor#ffcccc
int x, y, z, tmp;
if (z == 0)
  SWAP( x, y);

This will expand to:

Code Block
bgColor#ffcccc
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

...