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 do-while loop syntactically, so the macro can appear safely inside if clauses or other places that expect a single statement or a statement block. Note that this is only effective if none of the multiple statements are break or continue, as they would be captured by the do-while loop. (Alternatively, when an if, for, or while statement uses braces even for a single body statement, then multiple statements in a macro will expand correctly even without a do-while loop (see EXP19-C. Use braces for the body of an if, for, or while statement).

...

Improperly wrapped statement macros can result in unexpected and difficult to diagnose behavior.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

PRE10-C

Medium

Probable

Low

P12

L1

Automated Detection

ToolVersionCheckerDescription
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-PRE10
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C3412, C3458
Klocwork
Include Page
Klocwork_V
Klocwork_V
MISRA.DEFINE.BADEXP
 

LDRA tool suite
Include Page
LDRA_V
LDRA_V
79 SEnhanced enforcement
PRQA QA
PC-
C
lint Plus

Include Page

PRQA QA

PC-

C

lint Plus_

v

V

PRQA QA

PC-

C

lint Plus_

v

V

3412, 3458

Fully implemented

9502

Fully supported

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rec. PRE10-CChecks for macros with multiple statements (rule fully covered)

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

ISO/IEC TR 24772:2013Pre-processor Directives [NMP]

Bibliography

...


...

Image Modified Image Modified Image Modified