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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "return|break|continue|throw"))
|
if (Token::Match(tok, "return|break|continue|throw|goto"))
|
||||||
ret = true;
|
ret = true;
|
||||||
else if (ret && tok->str() == ";")
|
else if (ret && tok->str() == ";")
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1801,7 +1801,7 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// return, break, continue
|
// return, break, continue, goto
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" if (y == 1) { return; }\n"
|
" if (y == 1) { return; }\n"
|
||||||
|
@ -1820,6 +1820,17 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
// for, while
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue