Fixed #1072 (False positive: class member initialization with '*p=0;')
This commit is contained in:
parent
e3e39fc073
commit
01cfa3b6bd
|
@ -213,7 +213,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
Assign = false;
|
||||
}
|
||||
|
||||
if (ftok->str() == "}")
|
||||
else if (ftok->str() == "}")
|
||||
{
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
|
@ -243,6 +243,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
|
||||
if (!Token::Match(ftok->next(), "%var%") &&
|
||||
!Token::Match(ftok->next(), "this . %var%") &&
|
||||
!Token::Match(ftok->next(), "* %var% =") &&
|
||||
!Token::Match(ftok->next(), "( * this ) . %var%"))
|
||||
continue;
|
||||
|
||||
|
@ -309,6 +310,12 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
|||
initVar(varlist, ftok->strAt(0));
|
||||
}
|
||||
|
||||
// Assignment of array item of member variable?
|
||||
else if (Token::Match(ftok, "* %var% ="))
|
||||
{
|
||||
initVar(varlist, ftok->strAt(1));
|
||||
}
|
||||
|
||||
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
||||
if (Token::Match(ftok, "%var% . clear|Clear ("))
|
||||
{
|
||||
|
|
|
@ -49,7 +49,8 @@ private:
|
|||
TEST_CASE(uninitVarEnum);
|
||||
TEST_CASE(uninitVarStream);
|
||||
TEST_CASE(uninitVarTypedef);
|
||||
TEST_CASE(uninitVarArray);
|
||||
TEST_CASE(uninitVarArray1);
|
||||
TEST_CASE(uninitVarArray2);
|
||||
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
|
||||
TEST_CASE(privateCtor1); // If constructor is private..
|
||||
TEST_CASE(privateCtor2); // If constructor is private..
|
||||
|
@ -410,7 +411,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray()
|
||||
void uninitVarArray1()
|
||||
{
|
||||
checkUninitVar("class John\n"
|
||||
"{\n"
|
||||
|
@ -470,6 +471,19 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'John::a'\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarArray2()
|
||||
{
|
||||
checkUninitVar("class John\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" John() { *name = 0; }\n"
|
||||
"\n"
|
||||
"private:\n"
|
||||
" char name[255];\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitMissingFuncDef()
|
||||
{
|
||||
// Unknown member function
|
||||
|
|
Loading…
Reference in New Issue