...
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).
...
The do-while loop will always be executed exactly once.
This macro still violates the recommendation PRE12-C. Do not define unsafe macros, because both macro arguments are evaluated twice. It is expected that the arguments are simple lvalues.
Risk Assessment
Improperly wrapped statement macros can result in unexpected and difficult to diagnose behavior.
Recommendation | Severity | Likelihood |
|---|
Remediation CostDetectable | Repairable | Priority | Level |
|---|
PRE10-C | Medium | Probable | Yes |
LowAutomated Detection
| | PRQA QACPRQA QACvPRQA QACv3412, 3458
| Fully implementedRelated Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
Bibliography
...
...
Image Modified
Image Modified
Image Modified