Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
langc
#define INCREMENTINCREMOD(x, max) ((x) = ((x) + 1) % (max));

int index = 0;
int value;
value = INCREMENTINCREMOD(index, 10) + 2;
/* ... */

...

Code Block
bgColor#CCCCFF
langc
#define INCREMENTINCREMOD(x, max) ((x) = ((x) + 1) % (max))

Compliant Solution

This compliant solution uses an inline function as recommended by PRE00-C. Prefer inline or static functions to function-like macros.

Code Block
bgColor#CCCCFF
langc
inline int incremod(int *x, int max) {*x = (*x + 1) % max;}

Risk Assessment

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

ToolVersionCheckerDescription
PRQA QA-C Include PagePRQA_VPRQA_V3412Partially implemented
Astrée
Include Page
Astrée_V
Astrée_V
macro-final-semicolonFully checked
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-PRE11
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
LANG.PREPROC.MACROENDMacro Does Not End With ) or }
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C3412
LDRA tool suite
Include Page
LDRA_V
LDRA_V
79 SEnhanced Enforcement
PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

823

Fully supported

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rec. PRE11-CChecks for macros terminated with semicolons (rule fully covered)
RuleChecker
Include Page
RuleChecker_V
RuleChecker_V
macro-final-semicolon Fully checked

Related Vulnerabilities

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

Related Guidelines

...


...

Image Modified Image Modified Image Modified