An extraneous semicolon should be avoided to prevent an unintentional logic change
- STRAY_SEMICOLON
- Error
- Medium
- cwe
This rule applies when an extraneous semicolon causes an unintentional logic change.
Logic may be changed unintentionally due to an extraneous semicolon inserted in front of then
or else
part of a conditional statement or body part of a loop statement.
Noncompliant Code Example
View with compliant examples side by side// Example 1
if (cond); // STRAY_SEMICOLON alarm
doSomething();
// Example 2
while (++x <= 10) ; // STRAY_SEMICOLON alarm
{
sum += x;
}
Compliant Code Example
View with noncompliant examples side by side// Example 1
if (cond)
doSomething();
// Example 2
while (++x <= 10)
{
sum += x;
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.