Uninitialized variables: detect uninitialized pointer array

This commit is contained in:
Daniel Marjamäki 2009-11-10 19:35:54 +01:00
parent c301dc1907
commit 39614a699e
2 changed files with 15 additions and 0 deletions

View File

@ -138,6 +138,12 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses)
varname = next->strAt(1); varname = next->strAt(1);
} }
// Pointer array?
else if (Token::Match(next, "%type% * %var% ["))
{
varname = next->strAt(2);
}
// std::string.. // std::string..
else if (withClasses && Token::Match(next, "std :: string %var% ;")) else if (withClasses && Token::Match(next, "std :: string %var% ;"))
{ {

View File

@ -445,6 +445,15 @@ private:
" A a[5];\n" " A a[5];\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("class A;\n"
"class John\n"
"{\n"
"public:\n"
" John() { }\n"
" A *a[5];\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5]: (style) Member variable not initialized in the constructor 'John::a'\n", errout.str());
} }
void uninitMissingFuncDef() void uninitMissingFuncDef()