Fix #1022 (False positive: uninitialized variable when using local struct)
This commit is contained in:
parent
f1ae932f18
commit
ded2e68c2e
|
@ -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() == "}")
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue