CertC-MSC13

Detect and remove unused values

Required inputs: IR, StaticSemanticAnalysis

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

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.

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
Related Guidelines
SEI CERT C++ Coding Standard VOID MSC13-CPP. Detect and remove unused values
ISO/IEC TR 24772 Likely Incorrect Expressions [KOA]
Dead and Deactivated Code [XYQ]
Unused Variable [XYR]
Bibliography
[ Coverity 2007 ]
Excerpt from SEI CERT C Coding Standard: Rules for Developing Safe, Reliable, and Secure Systems (2016 Edition) and SEI CERT C Coding Standard [https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/recommendations/miscellaneous-msc/msc13-c], Copyright (C) 1995-2026 Carnegie Mellon University. See 9.4 3rd-Party Licenses in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

conditional_unused_def

Result of assignment is not used along some path(s)

None

True

init_used_in_other_isr

Initialization is not used except within code reached from an entry point that might be triggered by an interrupt

None

True

unused_catch_parameter

Unused implicit initialization of catch clause parameter (you can use an unnamed one instead)

None

False

unused_def

Result of assignment is not used

None

False

unused_init

Unused initialization

None

False

used_in_other_isr

Result of assignment is not used except within code reached from an entry point that might be triggered by an interrupt

None

True

Options

report_dead_initializations

report_dead_initializations : bool = True

Whether initializations may be reported as dead.