Fixed #2478 (Crash when trying to analyze files (CheckClass::checkReturnPtrThis))

This commit is contained in:
Robert Reif 2011-01-21 19:54:41 +01:00 committed by Daniel Marjamäki
parent 8cec4e6de6
commit 767e01e24a
2 changed files with 29 additions and 2 deletions

View File

@ -908,7 +908,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
// check if it is a member function
for (it = scope->functionList.begin(); it != scope->functionList.end(); ++it)
{
// check for a regular function with the same name and a bofy
// check for a regular function with the same name and a body
if (it->type == Function::eFunction && it->hasBody &&
it->token->str() == tok->next()->str())
{
@ -918,7 +918,16 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
{
// make sure it's not a const function
if (it->arg->link()->next()->str() != "const")
checkReturnPtrThis(scope, &*it, it->arg->link()->next(), it->arg->link()->next()->link());
{
/** @todo make sure argument types match */
// make sure it's not the same function
if (&*it != func)
checkReturnPtrThis(scope, &*it, it->arg->link()->next(), it->arg->link()->next()->link());
// just bail for now
else
return;
}
}
}
}

View File

@ -104,6 +104,7 @@ private:
TEST_CASE(operatorEqRetRefThis3); // ticket #1405
TEST_CASE(operatorEqRetRefThis4); // ticket #1451
TEST_CASE(operatorEqRetRefThis5); // ticket #1550
TEST_CASE(operatorEqRetRefThis6); // ticket #2479
TEST_CASE(operatorEqToSelf1); // single class
TEST_CASE(operatorEqToSelf2); // nested class
TEST_CASE(operatorEqToSelf3); // multiple inheritance
@ -475,6 +476,23 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to self\n", errout.str());
}
void operatorEqRetRefThis6() // ticket #2478 (segmentation fault)
{
checkOpertorEqRetRefThis(
"class UString {\n"
"public:\n"
" UString& assign( const char* c_str );\n"
" UString& operator=( const UString& s );\n"
"};\n"
"UString& UString::assign( const char* c_str ) {\n"
" std::string tmp( c_str );\n"
" return assign( tmp );\n"
"}\n"
"UString& UString::operator=( const UString& s ) {\n"
" return assign( s );\n"
"}\n");
}
// Check that operator Equal checks for assignment to self
void checkOpertorEqToSelf(const char code[])
{