Unnecessary if conditional
This defect occurs on if-statements where
the condition is always true. This defect occurs only on
if-statements that do not have an else-statement.
This defect shows unnecessary if-statements when there is
no difference in code execution if the
if-statement is removed.
Unnecessary if statements often indicate a coding error.
Perhaps the if condition is coded incorrectly or the
if statement is not required at all.
The fix depends on the root cause of the defect. For instance, the root cause can be an error condition that is checked twice on the same execution path, making the second check redundant.
Often the result details show a sequence of events that led to the defect. You can implement the fix on any event in the sequence. If the result details do not show the event history, you can trace back using right-click options in the source code and see previous related events. See also Interpret Bug Finder Results in Polyspace Desktop User Interface.
See examples of fixes below.
If the redundant condition represents defensive coding practices and you do not want to fix the issue, add comments to your result or code to avoid another review. See Address Polyspace Results Through Bug Fixes or Justifications.
| Group: Data flow |
| Language: C | C++ |
| Default: On |
Command-Line Syntax: USELESS_IF |
| Impact: Medium |
Code deactivated by constant false condition | Dead code | Find defects (-checkers) | Unreachable code