Skip to main content
GitHub

MSC13-C. Detect and remove unused values

The presence of unused values may indicate significant logic errors. To prevent such errors, unused values should be identified and removed from code.

This recommendation is a specific case of MSC12-C. Detect and remove code that has no effect or is never executed .

Noncompliant Code Example

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 ).

Non-compliant code
int *p1;
int *p2;
p1 = foo();
p2 = bar();

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

Compliant Solution

This example can be corrected in many different ways, depending on the intent of the programmer. In this compliant solution, p2 is found to be extraneous. The calls to bar() and baz() can be removed if they do not produce any side effects.

Compliant code
int *p1 = foo();

/* Removable if bar() does not produce any side effects */
(void)bar();

/* Removable if baz() does not produce any side effects */
(void)baz();
return p1;

Exceptions

MSC13-EX1: Initializing a variable with a default value, such as 0, which gets subsequently overwritten may be inefficient, but is less of a problem than reading an uninitialized value, as per EXP33-C. Do not read uninitialized memory .

Risk Assessment

Unused values may indicate significant logic errors.

Recommendation Severity Likelihood Detectable Repairable Priority Level
MSC13-C Low Unlikely Yes Yes P3 L3

Automated Detection

ToolVersionCheckerDescription
Astrée
25.10
dead-assignment
dead-initializer
unused-local-variable
unused-parameter
Partially checked
Codee
2025.4.9
PWR028
PWR030
PWR082
PWR086
Remove pointer increment preventing performance optimization
Remove pointer assignment preventing performance optimization for perfectly nested loops
Remove unused variables
Prefer array-based notation over pointer-based notation for readability
CodeSonar
9.2p0
LANG.STRUCT.UUVALUnused value
Coverity
2017.07
UNUSED_VALUEFinds variables that are assigned pointer values returned from a function call but never used
Helix QAC
2025.2
C1500, C1502, C3203, C3205, C3206, C3207, C3229
DF2980, DF2981, DF2982, DF2983, DF2984, DF2985, DF2986
Klocwork
2025.2
LV_UNUSED.GEN
VA_UNUSED.GEN
VA_UNUSED.INIT
LDRA tool suite
9.7.1
1 D , 8 D, 105 D, 94 D, 15 DFully implemented
Parasoft C/C++test
2026.1
CERT_C-MSC13-aAvoid unnecessary local variables
PC-lint Plus
1.4
438, 505, 529, 715, 838Partially supported
Polyspace Bug Finder
R2025b
CERT C: Rec. MSC13-CChecks for:
  • Unused parameter
  • Write without a further read
Rec. partially covered.
PVS-Studio
7.43
V519 , V596 , V603 , V714 , V744 , V751 , V763 , V1001 , V5003
RuleChecker
25.10
dead-assignment
dead-initializer
unused-local-variable
unused-parameter
Partially checked
SonarQube C/C++ Plugin
3.11
S1854

Search for vulnerabilities resulting from the violation of this rule on the CERT website .

ISO/IEC TR 24772Likely Incorrect Expressions [KOA]
Dead and Deactivated Code [XYQ]
Unused Variable [XYR]

Bibliography

[ Coverity 2007 ]