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;
|
Assign = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftok->str() == "}")
|
else if (ftok->str() == "}")
|
||||||
{
|
{
|
||||||
if (indentlevel <= 1)
|
if (indentlevel <= 1)
|
||||||
break;
|
break;
|
||||||
|
@ -243,6 +243,7 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
||||||
|
|
||||||
if (!Token::Match(ftok->next(), "%var%") &&
|
if (!Token::Match(ftok->next(), "%var%") &&
|
||||||
!Token::Match(ftok->next(), "this . %var%") &&
|
!Token::Match(ftok->next(), "this . %var%") &&
|
||||||
|
!Token::Match(ftok->next(), "* %var% =") &&
|
||||||
!Token::Match(ftok->next(), "( * this ) . %var%"))
|
!Token::Match(ftok->next(), "( * this ) . %var%"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -309,6 +310,12 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
||||||
initVar(varlist, ftok->strAt(0));
|
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.
|
// The functions 'clear' and 'Clear' are supposed to initialize variable.
|
||||||
if (Token::Match(ftok, "%var% . clear|Clear ("))
|
if (Token::Match(ftok, "%var% . clear|Clear ("))
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,7 +49,8 @@ private:
|
||||||
TEST_CASE(uninitVarEnum);
|
TEST_CASE(uninitVarEnum);
|
||||||
TEST_CASE(uninitVarStream);
|
TEST_CASE(uninitVarStream);
|
||||||
TEST_CASE(uninitVarTypedef);
|
TEST_CASE(uninitVarTypedef);
|
||||||
TEST_CASE(uninitVarArray);
|
TEST_CASE(uninitVarArray1);
|
||||||
|
TEST_CASE(uninitVarArray2);
|
||||||
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
|
TEST_CASE(uninitMissingFuncDef);// can't expand function in constructor
|
||||||
TEST_CASE(privateCtor1); // If constructor is private..
|
TEST_CASE(privateCtor1); // If constructor is private..
|
||||||
TEST_CASE(privateCtor2); // If constructor is private..
|
TEST_CASE(privateCtor2); // If constructor is private..
|
||||||
|
@ -410,7 +411,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarArray()
|
void uninitVarArray1()
|
||||||
{
|
{
|
||||||
checkUninitVar("class John\n"
|
checkUninitVar("class John\n"
|
||||||
"{\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());
|
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()
|
void uninitMissingFuncDef()
|
||||||
{
|
{
|
||||||
// Unknown member function
|
// Unknown member function
|
||||||
|
|
Loading…
Reference in New Issue