sqc 0.4.13

Software Code Quality - CERT C compliance checker
[metadata]
id = "PRE10-C"
type = "recommendation"
category = "PRE"
number = 10
title = "Wrap multistatement macros in a do-while loop"
description = """
Macros are often used to execute a sequence of multiple statements as a group.
Inline functions are, in general, more suitable for this task (seePRE00-C.
Prefer inline or static functions to function-like macros). Occasionally,
however, they are not feasible (when macros are expected to operate on variables
of different types, for example). When multiple statements are used in a macro,
they should be bound together in ado-whileloop syntactically, so the macro can
appear safely insideifclauses or other places that expect a single statement or
a statement block. Note that this is only effective if none of the multiple
statements arebreakorcontinue, as they would be captured by thedo-whileloop.
(Alternatively, when anif,for, orwhilestatement uses braces even for a single
body statement, then multiple statements in a macro will expand correctly even
without ado-whileloop (seeEXP19-C. Use braces for the body of an if, for, or
while statement).
"""
severity = "Medium"
likelihood = "Probable"
priority = "P12"
level = "L1"
cert_version = "2016 Edition (Wiki)"
last_modified = "Unknown"

[rules.cert_c.PRE10-C]
enabled = true

[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/PRE10-C.+Wrap+multistatement+macros+in+a+do-while+loop"