...
Code Block | ||||
---|---|---|---|---|
| ||||
#define INCREMENTINCREMOD(x, max) ((x) = ((x) + 1) % (max)); int index = 0; int value; value = INCREMENTINCREMOD(index, 10) + 2; /* ... */ |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#define INCREMENTINCREMOD(x, max) ((x) = ((x) + 1) % (max)) |
...
Code Block | ||||
---|---|---|---|---|
| ||||
inline int incrementincremod(int *x, int max) {*x = (*x + 1) % max;} |
...
Using a semicolon at the end of a macro definition can result in the change of program control flow and thus unintended program behavior.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
PRE11-C | Medium | Probable | Low | P12 | L1 |
Automated Detection
Tool | Version | Checker | Description |
---|
Astrée |
| macro-final-semicolon | Fully checked | ||||||
Axivion Bauhaus Suite |
| CertC-PRE11 | |||||||
CodeSonar |
| LANG.PREPROC.MACROEND | Macro Does Not End With ) or } | ||||||
Helix QAC |
| C3412 | |||||||
LDRA tool suite |
| 79 S | Enhanced Enforcement | ||||||
PC-lint Plus |
| 823 | Fully supported | ||||||
Polyspace Bug Finder |
| CERT C: Rec. PRE11-C | Checks for macros terminated with semicolons (rule fully covered) | ||||||
RuleChecker |
| macro-final-semicolon | Fully checked |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
SEI CERT C++ |
Coding Standard | VOID PRE11-CPP. Do not conclude macro definitions with a semicolon |
...
...