Static Analysis Problem Type Reference

Unused variable value

A value was assigned that was never read.

An unused variable value is harmless in itself, but it may indicate that the code that was intended to consume this value was either deleted or moved to a location that is not reached by this assignment. It is a good idea to track down the reason why this value was not consumed as that could indicate a subtle logic error.

This condition is listed as CWE-563 (Unused Variable) in the Common Weakness Enumeration, a community-developed dictionary of software weakness types.

ID

Code location

Description

1

Memory write

The location where the unused value was assigned

Example


// Release storage allocated for job.
// If job_type is 1, free val1;
// Otherwise free val2 and either val3 or val4, depending on job type

void clean_up(int job_type, char *val1, char *val2, char *val3, char *val4)
{
   char * free_me;
   if (job_type == 1) {
      free_me = val1; // unused value: will not be freed
   } else {
      free(val2);
      if (job_type == 3) {
         free_me = val3;
      } else {
         free_me = val4;
      }
      free(free_me); // oops: this belongs AFTER the curly brace
   }
}