Write without a further read
Variable never read after assignment
Description
This defect occurs when a value assigned to a variable is never read.
For instance, you write a value to a variable and then write a second value before reading the previous value. The first write operation is redundant.
This defect is not reported on pointers that are written to but not read in a function because the pointer can be an alias of a variable that is used elsewhere.
Risk
Redundant write operations often indicate programming errors. For instance, you forgot to read the variable between two successive write operations or unintentionally read a different variable.
Fix
Identify the reason why you write to the variable but do not read it later. Look for common programming errors such as accidentally reading a different variable with a similar name.
If you determine that the write operation is redundant, remove the operation.
Examples
Result Information
Group: Data flow |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: USELESS_WRITE |
Impact: Low |
Version History
Introduced in R2013bSee Also
Find defects (-checkers)
| MISRA C:2012 Rule 2.2
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)