Versions Compared

Key

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

Code that is executed but does not perform any action, or has an unintended effect, most likely results from a coding error and can result in can cause unexpected behavior. Statements or expressions that have no effect should be identified and removed from code. Most modern compilers can warn about code that has no effect in many cases. (See recommendation MSC00-C. Compile cleanly at high warning levels.)

This recommendation is related to guideline MSC07-C. Detect and remove dead code.

...

Code Block
bgColor#FFCCCC
langc

int a;
int b;
/* ... */
a == b;

This is code is likely a case of the programmer mistakenly using the equals operator == instead of the assignment operator =.

...

Code Block
bgColor#ccccff
langc

int a;
int b;
/* ... */
a = b;

...

In this example, a pointer increment and then a dereference occursoccur. However, the dereference has no effect.

Code Block
bgColor#FFCCCC
langc

int *p;
/* ... */
*p++;

Compliant Solution (Dereference)

...

Code Block
bgColor#ccccff
langc

int *p;
/* ... */
p++;

If the intent was to increment the value referred to by p, then parentheses can be used to ensure p is dereferenced and then incremented. (See recommendation EXP00-C. Use parentheses for precedence of operation.)

Code Block
bgColor#ccccff
langc

int *p;
/* ... */
(*p)++;

Compliant Solution (Memory-Mapped Devices)

Another possibility is that p is being used to reference a memory-mapped device. In this case, the variable p should be declared as volatile.

Code Block
bgColor#ccccff
langc

volatile int *p;
/* ... */
(void) *p++;

...

Klocwork

Tool

Version

Checker

Description

Coverity Prevent

Include Page
Coverity_V
Coverity_V

NO_EFFECT

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

GCC

3.0

-Wunused-value and -Wunused-parameter

Options detect unused local variables or non-constant nonconstant static variables , and unused function parameters, respectively.

Section
Include Page
Klocwork_V
Klocwork_V
section

EFFECT

 

section

LDRA tool suite

Include Page
LDRA_V
LDRA_V
section

65 D
70 D
57 S

section

Fully

Implemented section

implemented.

Splint

Include Page
Splint_V
Splint_V

 

 

...

ISO/IEC TR 24772 "BRS Leveraging human experience," "BVQ Unspecified Functionalityfunctionality," "KOA Likely incorrect expressions," and "XYQ Dead and Deactivated Codedeactivated code"

MISRA Rule 14.1 and Rule 14.2

...

Sources

[Coverity 2007]

...