Improve dangerous iterator usage (after erase()) message.
See forum thread: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192
This commit is contained in:
parent
b750a52f6d
commit
66e8b7bc1e
|
@ -454,15 +454,15 @@ void CheckStl::erase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error message for bad iterator usage..
|
// Error message for bad iterator usage..
|
||||||
void CheckStl::eraseError(const Token *tok)
|
void CheckStl::eraseError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "erase", "Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.");
|
reportError(tok, Severity::error, "erase",
|
||||||
|
"Dangerous iterator usage after erase()-method.\n"
|
||||||
|
"The iterator is invalid after it has been used in erase() function. "
|
||||||
|
"Dereferencing or comparing it with another iterator is invalid operation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CheckStl::pushback()
|
void CheckStl::pushback()
|
||||||
{
|
{
|
||||||
// Pointer can become invalid after push_back or push_front..
|
// Pointer can become invalid after push_back or push_front..
|
||||||
|
|
|
@ -369,7 +369,7 @@ private:
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("for (it = foo.begin(); it != foo.end(); ++it)\n"
|
check("for (it = foo.begin(); it != foo.end(); ++it)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -379,8 +379,8 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n"
|
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator usage after erase()-method.\n"
|
||||||
"[test.cpp:7]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
"[test.cpp:7]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("void f(std::list<int> &ints)\n"
|
check("void f(std::list<int> &ints)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -437,7 +437,7 @@ private:
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -447,7 +447,7 @@ private:
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -457,7 +457,7 @@ private:
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -467,7 +467,7 @@ private:
|
||||||
" foo.erase(++it);\n"
|
" foo.erase(++it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase5()
|
void erase5()
|
||||||
|
@ -482,7 +482,7 @@ private:
|
||||||
" foo.erase(it);\n"
|
" foo.erase(it);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void eraseBreak()
|
void eraseBreak()
|
||||||
|
@ -496,7 +496,7 @@ private:
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -597,7 +597,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void eraseGoto()
|
void eraseGoto()
|
||||||
|
|
Loading…
Reference in New Issue