Infinite loop
Description
This defect occurs when a loop termination condition is never satisfied after the loop is entered.
The checker skips intentional infinite loops such as while(1)
. Code following intentional infinite loops are flagged by the Unreachable code
checker.
Risk
Unintended infinite loops often indicate an error in the program logic. For instance, one of the following programming errors might have occurred:
The loop index is never updated inside the loop.
The loop index is updated in branches inside the loop that are unreachable.
The loop index is updated in a way that the index never satisfies the loop termination condition.
Fix
Fix the programming error if any. Make sure that the loop index update is reachable, and the loop index eventually acquires a value that makes the loop terminate.
If you determine that the loop termination condition is satisfied under certain circumstances (false positive), add comments to your result or code to avoid another review. See
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
Group: Data flow |
Language: C | C++ |
Default: On |
Command-Line Syntax: INFINITE_LOOP |
Impact: High |
Version History
Introduced in R2023a
See Also
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)