You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Either the condition 'x' is redundant or function 'erase()' is called on the iterator 'iter' which is out of bounds.", CWE628, Certainty::normal);
3129
+
return;
3130
+
}
3131
+
const std::string& func = ftok->str();
3132
+
const std::string iter = itertok->expressionString();
3133
+
3134
+
constbool isConditional = val->isPossible();
3135
+
std::string msg;
3136
+
if (isConditional) {
3137
+
msg = ValueFlow::eitherTheConditionIsRedundant(val->condition) + " or function '" + func + "()' is called on the iterator '" + iter + "' which is out of bounds.";
3138
+
} else {
3139
+
msg = "Calling function '" + func + "()' on the iterator '" + iter + "' which is out of bounds.";
ASSERT_EQUALS("[test.cpp:3]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds.\n",
2217
+
errout.str());
2218
+
2219
+
check("void f() {\n"
2220
+
" std::vector<int> v;\n"
2221
+
" ((v).erase)(v.begin());\n"
2222
+
"}\n");
2223
+
ASSERT_EQUALS("[test.cpp:3]: (error) Calling function 'erase()' on the iterator 'v.begin()' which is out of bounds.\n",
2224
+
errout.str());
2225
+
}
2226
+
2163
2227
// Dereferencing invalid pointer
2164
2228
voiddereference() {
2165
2229
check("void f()\n"
@@ -2219,7 +2283,9 @@ class TestStl : public TestFixture {
2219
2283
" ints.erase(iter);\n"
2220
2284
" std::cout << iter->first << std::endl;\n"
2221
2285
"}");
2222
-
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str());
2286
+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n"
2287
+
"[test.cpp:6]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds.\n",
2288
+
errout.str());
2223
2289
2224
2290
// Reverse iterator
2225
2291
check("void f()\n"
@@ -2230,7 +2296,9 @@ class TestStl : public TestFixture {
2230
2296
" ints.erase(iter);\n"
2231
2297
" std::cout << iter->first << std::endl;\n"
2232
2298
"}");
2233
-
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str());
2299
+
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n"
2300
+
"[test.cpp:6]: (error) Calling function 'erase()' on the iterator 'iter' which is out of bounds.\n",
0 commit comments