...
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).
...
Recommendation | Severity | Likelihood | Detectable | Remediation CostRepairable | Priority | Level |
|---|---|---|---|---|---|---|
PRE10-C | Medium | Probable | Yes | LowYes | P12 | L1 |
Automated Detection
| Tool | Version | Checker | Description | |||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Axivion Bauhaus Suite |
| CertC-PRE10 | ||||||||||||||||||||||||
| Helix QAC |
| C3412, C3458 | ||||||||||||||||||||||||
| Klocwork |
| MISRA.DEFINE.BADEXP | ||||||||||||||||||||||||
| LDRA tool suite |
| 79 S | Enhanced enforcementPRQA QA | |||||||||||||||||||||||
| PC- | Clint Plus |
| PRQA QA
| C
| v
| PRQA QA
| C
| v
| 3412, 3458 | 9502 | Fully supported | |||||||||||||||
| Polyspace Bug Finder |
| CERT C: Rec. PRE10-C | Checks for macros with multiple statements (rule fully covered)Fully implemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
| ISO/IEC TR 24772:2013 | Pre-processor Directives [NMP] |
...