Fix #1022 (False positive: uninitialized variable when using local struct)

This commit is contained in:
Daniel Marjamäki 2009-11-29 19:23:31 +01:00
parent f1ae932f18
commit ded2e68c2e
2 changed files with 19 additions and 0 deletions

View File

@ -1458,6 +1458,13 @@ void CheckOther::uninitvar()
unsigned int indentlevel = 0;
for (; tok; tok = tok->next())
{
// skip structs
if (Token::Match(tok->previous(), "[;{}] struct %var% {"))
{
tok = tok->tokAt(2)->link();
continue;
}
if (tok->str() == "{")
++indentlevel;
else if (tok->str() == "}")

View File

@ -1229,6 +1229,18 @@ private:
" char *s2 = new char[strlen(s1)];\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str());
// struct..
checkUninitVar("void f()\n"
"{\n"
" struct Relative {\n"
" Surface *surface;\n"
" void MoveTo(int x, int y) {\n"
" surface->MoveTo();\n"
" }\n"
" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}