Uninitialized variables: Fixed false positives when goto is used.
This commit is contained in:
parent
8eb067358c
commit
025518c474
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue