Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added sonarqube example and new nce/cs pair

...

Code Block
bgColor#ccccff
langc
volatile int *p;
/* ... */
(void) *(p++);

Noncompliant Code Example (if/else if)

A chain of if/else if statements is evaluated from top to bottom. At most, only one branch of the chain will be executed: the first one with a condition that evaluates to true. Consequently, duplicating a condition in a sequence of if/else if statements automatically leads to dead code.

Code Block
bgColor#FFCCCC
langc
if (param == 1)
   openWindow();
 else if (param == 2)
   closeWindow();
 else if (param == 1) /* Duplicated condition */
   moveWindowToTheBackground();

Compliant Solution (if/else if)

In this compliant solution, the third conditional expression has been corrected.

Code Block
bgColor#ccccff
langc
if (param == 1)
   openWindow();
 else if (param == 2)
   closeWindow();
 else if (param == 3)
   moveWindowToTheBackground();

Risk Assessment

The presence of code that has no effect can indicate logic errors that may result in unexpected behavior and vulnerabilities.

...

Tool

Version

Checker

Description

CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

LANG.STRUCT.EBS

LANG.STRUCT.RC

MISC.NOEFFECT

Empty {Branch, for, if, switch, while} Statement

Redundant Condition

Funcion Call Has No Effect

Coverity

Include Page
Coverity_V
Coverity_V

NO_EFFECT

Finds statements or expressions that do not accomplish anything or statements that perform an unintended action

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.MSC12

Partially implemented

GCC

3.0

-Wunused-value
-Wunused-parameter

Options detect unused local variables or nonconstant static variables and unused function parameters, respectively

Klocwork

Include Page
Klocwork_V
Klocwork_V

EFFECT

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

65 D
70 D
57 S

Fully implemented

PRQA QA-C
Include Page
PRQA QA-C_v
PRQA QA-C_v

3426,3427,3307,3110,3112,3404

Partially implemented
SonarQube 
Include Page
SonarQube_v
SonarQube_v
 S1862 

Splint

Include Page
Splint_V
Splint_V

 

 

...

Bibliography

 

...