Fixed #4718 (False positive: unititialized variable (value flow))

This commit is contained in:
Daniel Marjamäki 2013-04-08 19:34:39 +02:00
parent c0ad2a209c
commit 894a2435ae
2 changed files with 11 additions and 0 deletions

View File

@ -1235,6 +1235,9 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
return true; return true;
} }
if (alwaysTrue && noreturnIf)
return true;
std::map<unsigned int, int> varValueIf; std::map<unsigned int, int> varValueIf;
if (!initif && !noreturnIf) { if (!initif && !noreturnIf) {
for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) { for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {

View File

@ -2563,6 +2563,14 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar2("int f(int x) {\n"
" int y;\n"
" if (x) y = do_something();\n"
" if (!x) return 0;\n"
" return y;\n"
"}");
ASSERT_EQUALS("", errout.str());
// Unknown => bail out.. // Unknown => bail out..
checkUninitVar2("void f(int x) {\n" checkUninitVar2("void f(int x) {\n"
" int i;\n" " int i;\n"