Versions Compared

Key

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

...

In this noncompliant code example, a semicolon is used on the same line as an if statement.:

Code Block
bgColor#FFcccc
langc
if (a == b); {
  /* ... */
}

...

It is likely, in this example, that the semicolon was accidentally inserted.:

Code Block
bgColor#ccccff
langc
if (a == b) {
  /* ... */
}

Risk Assessment

Errors of omission can result in unintended program flow.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

EXP15-C

High

Likely

Low

P27

L1


Automated Detection

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V
empty-bodyFully checked
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-EXP15Fully implemented
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
LANG.STRUCT.EBSEmpty branch statement
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C3109
Klocwork
Include Page
Klocwork_V
Klocwork_V

SEMICOL

 


LDRA tool suite
Include Page
LDRA_V
LDRA_V
11 S, 12 S, 428 SFully Implemented
Parasoft C/C++test

Include Page
Parasoft_V
Parasoft_V

CERT_C-EXP15-aSuspicious use of semicolon
PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

721, 722

Partially supported: reports missing body from if, for, or while with semi-colon immediately following predicate

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rec. EXP15-CChecks for semicolon on same line as for, if or while statement (rule fully covered)
PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V529, V715
SonarQube C/C++ Plugin
Include Page
SonarQube C/C++ Plugin_V
SonarQube C/C++ Plugin_V
S1116
RuleChecker
Include Page
RuleChecker_V
RuleChecker_V
empty-bodyFully checked

Related Guidelines

SEI CERT Oracle
Secure
Coding Standard for Java
MSC52
MSC51-
JG
J. Do not place a semicolon
on the same line as
immediately following an if, for, or while
statement
condition
ISO/IEC TR 24772:2013Likely
incorrect expression
Incorrect Expression [KOA]
MITRE CWECWE-480, Use of incorrect operator

Bibliography

[Hatton 1995]Section 2.7.2, "Errors of Omission and Addition"

...


...

Image Modified Image Modified Image Modified