Uninitialized variables: Fixed false positives when goto is used.

This commit is contained in:
Daniel Marjamäki 2011-12-26 16:46:10 +01:00
parent 8eb067358c
commit 025518c474
2 changed files with 13 additions and 2 deletions

View File

@ -1182,7 +1182,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
return true;
}
if (Token::Match(tok, "return|break|continue|throw"))
if (Token::Match(tok, "return|break|continue|throw|goto"))
ret = true;
else if (ret && tok->str() == ";")
return true;

View File

@ -1801,7 +1801,7 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// return, break, continue
// return, break, continue, goto
checkUninitVar2("void f() {\n"
" int x;\n"
" if (y == 1) { return; }\n"
@ -1820,6 +1820,17 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int i;\n"
" if (x) {\n"
" i = 1;\n"
" } else {\n"
" goto out;\n"
" }\n"
" i++;\n"
"}");
ASSERT_EQUALS("", errout.str());
// for, while
checkUninitVar2("void f() {\n"
" int x;\n"