Uninitialized variables: detect uninitialized pointer array
This commit is contained in:
parent
c301dc1907
commit
39614a699e
|
@ -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% ;"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue