Invalid iterator usage
Mismatched or uninitialized iterators are used in standard algorithm functions and comparison operations
Since R2022a
Description
This checker flags invalid use of iterators. For instance, this checker is raised when:
Iterators from mismatched containers are compared to each other.
Iterators from mismatched containers are passed to algorithms that expect iterators from the same container.
Uninitialized iterators are passed to a standard algorithm function or used in a comparison operation.
The
end()
iterator is passed as the only argument to thevector::erase()
method.
Risk
The preceding invalid uses of iterators might result in unexpected behavior.
Calling standard algorithms by using mismatched or uninitialized iterators might lead to segmentation faults or undefined behaviors.
Because mismatched iterators point to different containers, comparing them fails silently. This behavior might be unexpected and lead to bugs that are difficult to diagnose.
Fix
The preceding invalid use of iterators might indicate typographical errors or logic errors in your code. To fix such defects, use initialized iterators from the same container in standard algorithms and comparison operations.
Examples
Result Information
Group: Programming |
Language: C++ |
Default: Off |
Command-Line Syntax:
INVALID_ITERATOR_USAGE |
Impact: High |
Version History
Introduced in R2022a
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)