fix #2602 (segmentation fault of cppcheck ( class A {A& operator=(const A&); }; ))

This commit is contained in:
Robert Reif 2011-02-22 06:47:28 -05:00
parent 4e1ce93104
commit ba6c2ca310
2 changed files with 23 additions and 11 deletions

View File

@ -641,20 +641,23 @@ void CheckClass::privateFunctions()
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func)
{
const Token *ftok = func->start;
const Token *etok = ftok->link();
for (; ftok != etok; ftok = ftok->next())
if (ftok)
{
if (Token::Match(ftok, "%var% ("))
const Token *etok = ftok->link();
for (; ftok != etok; ftok = ftok->next())
{
// Remove function from FuncList
std::list<const Token *>::iterator it = FuncList.begin();
while (it != FuncList.end())
if (Token::Match(ftok, "%var% ("))
{
if (ftok->str() == (*it)->str())
FuncList.erase(it++);
else
++it;
// Remove function from FuncList
std::list<const Token *>::iterator it = FuncList.begin();
while (it != FuncList.end())
{
if (ftok->str() == (*it)->str())
FuncList.erase(it++);
else
++it;
}
}
}
}

View File

@ -39,6 +39,7 @@ private:
TEST_CASE(test3);
TEST_CASE(test4);
TEST_CASE(test5);
TEST_CASE(test6); // ticket #2602
// [ 2236547 ] False positive --style unused function, called via pointer
TEST_CASE(func_pointer1);
@ -225,6 +226,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void test6() // ticket #2602 segmentation fault
{
check("class A {\n"
" A& operator=(const A&);\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}