Versions Compared

Key

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

...

In this example, p2 is assigned the value returned by bar(), but that value is never used. Note this example assumes that foo() and bar() return valid pointers. (See DCL30-C. Declare objects with appropriate storage durations.)

Code Block
bgColor#FFCCCC
langc
int *p1, *p2;
p1 = foo();
p2 = bar();

if (baz()) {
  return p1;
}
else {
  p2 = p1;
}
return p2;

...

Tool

Version

Checker

Description

LDRA tool suite

Include Page
LDRA_V
LDRA_V

1 D
70 D
94 D
15 D

Fully implemented.

Coverity

Include Page
Coverity_V
Coverity_V

UNUSED_VALUE

Finds variables that are assigned pointer values returned from a function call but never used.

Klocwork

Include Page
Klocwork_V
Klocwork_V

 

Can detect violations of this rule with a number of checkers.

PRQA QA·CQA-C
Include Page
PRQA_V
PRQA_V
 Fully implemented

...

CERT C++ Secure Coding Standard: MSC13-CPP. Detect and remove unused values

ISO/IEC TR 24772 "BRS Leveraging human experience," "KOA Likely incorrect expressions," "XYQ Dead and deactivated code," and "XYR Unused variable"

Sources

[Coverity 2007]

...