ITR-mismatch-alg (C++ only)
In this section:
Synopsis
A pair of iterators passed to an STL algorithm function point to different containers.
Enabled by default
No
Severity/Certainty
High/Low

Full description
A pair of iterators passed to an STL algorithm function point to different containers. This can cause the application to access invalid memory, which might lead to a crash or a security vulnerability.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
#include <vector>
#include <algorithm>
void example(void) {
std::vector<int> v, w;
for (int i=0; i != 10; ++i) {
v.push_back(rand() % 100);
w.push_back(rand() % 100);
}
std::sort(v.begin(), w.end()); //v and w are different containers
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
#include <vector>
#include <algorithm>
void example(void) {
std::vector<int> v;
for (int i=0; i != 10; ++i) {
v.push_back(rand() % 100);
}
std::sort(v.begin(), v.end()); //OK
}