Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

ITER.INAPPROPRIATE.MULTIPLE

Iterators with inappropriate container object

The ITER checkers find problems with iterators in containers. The ITER.INAPPROPRIATE.MULTIPLE checker flags instances in which two iterators assigned to different containers are used together with a third container.

Vulnerability and risk

Using an invalid iterator typically results in undefined behavior. For example, using the iterator in the wrong container can result in unpredictable program actions. Code in which an iterator is used in an inappropriate container always provides a false result, so the algorithm won't behave as expected or intended.

Vulnerable code example

1   #include <set>
2   using namespace std;
3    
4 
5   void foo(set<int>& cont1, set<int>& cont2, set<int>& cont3)
6   {
7       set<int>::iterator i = cont1.find(100);
8       set<int>::iterator j = cont2.find(200);
9       cont3.insert(i, j);
10  }
11   
12  int main() 
13  {
14      return 0;
13  }

In this example, iterator 'i' and iterator 'j', assigned to 'cont1' and 'cont2', respectively, are used to specify a range for 'cont3', which will produce undefined results. Klocwork reports ITER.INAPPROPRIATE.MULTIPLE at line 9.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning C/C++ analysis for more information.