Fixed #2179 (Segmentation fault in assignment operator)

This commit is contained in:
Robert Reif 2010-11-09 06:58:19 +01:00 committed by Daniel Marjamäki
parent c2bf3647a4
commit 36b03bdd3e
3 changed files with 29 additions and 7 deletions

View File

@ -102,7 +102,7 @@ static bool isFunction(const Token *tok, const Token **funcStart, const Token **
return false;
}
void CheckClass::addFunction(SpaceInfo **info, const Token **tok)
void CheckClass::addFunction(SpaceInfo **info, const Token **tok, const Token *argStart)
{
const Token *tok1 = (*tok)->tokAt(-2);
int count = 0;
@ -180,6 +180,7 @@ void CheckClass::addFunction(SpaceInfo **info, const Token **tok)
{
func->hasBody = true;
func->token = (*tok)->next();
func->arg = argStart;
}
}
else if (func->tokenDef->str() == (*tok)->str())
@ -194,6 +195,7 @@ void CheckClass::addFunction(SpaceInfo **info, const Token **tok)
{
func->hasBody = true;
func->token = (*tok);
func->arg = argStart;
}
}
@ -203,6 +205,7 @@ void CheckClass::addFunction(SpaceInfo **info, const Token **tok)
// todo check for const
func->hasBody = true;
func->token = (*tok);
func->arg = argStart;
}
}
}
@ -256,7 +259,7 @@ void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
{
// class function
if ((*tok)->previous() && (*tok)->previous()->str() == "::")
addFunction(info, tok);
addFunction(info, tok, argStart);
// regular function
else
@ -271,7 +274,7 @@ void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
// class function
if (tok1->previous()->str() == "::")
addFunction(info, &tok1);
addFunction(info, &tok1, argStart);
// regular function
else
@ -479,7 +482,7 @@ void CheckClass::createSymbolDatabase()
// nested class function?
else if (tok->previous()->str() == "::" && isFunction(tok, &funcStart, &argStart))
addFunction(&info, &tok);
addFunction(&info, &tok, argStart);
// friend class declaration?
else if (Token::Match(tok, "friend class| %any% ;"))

View File

@ -279,7 +279,6 @@ private:
void addVar(const Token *token_, AccessControl access_, bool mutable_, bool static_, bool class_)
{
varlist.push_back(Var(token_, varlist.size(), access_, mutable_, static_, class_));
}
/**
@ -316,11 +315,10 @@ private:
bool isBaseClassFunc(const Token *tok);
};
void addFunction(SpaceInfo **info, const Token **tok);
void addFunction(SpaceInfo **info, const Token **tok, const Token *argStart);
void addNewFunction(SpaceInfo **info, const Token **tok);
void addIfFunction(SpaceInfo **info, const Token **tok);
/** @brief Information about all namespaces/classes/structrues */
std::list<SpaceInfo *> spaceInfoList;

View File

@ -104,6 +104,7 @@ private:
TEST_CASE(operatorEqToSelf5); // ticket # 1233
TEST_CASE(operatorEqToSelf6); // ticket # 1550
TEST_CASE(operatorEqToSelf7);
TEST_CASE(operatorEqToSelf8); // ticket #2179
TEST_CASE(memsetOnStruct);
TEST_CASE(memsetVector);
TEST_CASE(memsetOnClass);
@ -1234,6 +1235,26 @@ private:
ASSERT_EQUALS("", errout.str());
}
void operatorEqToSelf8()
{
checkOpertorEqToSelf(
"class FMat\n"
"{\n"
"public:\n"
" FMat& copy(const FMat& rhs);\n"
" FMat& operator=(const FMat& in);\n"
"};\n"
"FMat& FMat::copy(const FMat& rhs)\n"
"{\n"
" return *this;\n"
"}\n"
"FMat& FMat::operator=(const FMat& in)\n"
"{\n"
" return copy(in);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Check that base classes have virtual destructors
void checkVirtualDestructor(const char code[])
{