Uninitialized variables: Fixed false positives caused by recent improvement when variable is potentially initialized in else block.

This commit is contained in:
Daniel Marjamäki 2011-12-26 18:17:13 +01:00
parent c56e2e7cf9
commit 481fa532a8
2 changed files with 9 additions and 1 deletions

View File

@ -1157,7 +1157,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
if (initif && initelse)
return true;
if (initif || initelse)
if (initif || initelse || possibleInitElse)
++number_of_if;
}
}

View File

@ -1909,6 +1909,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int a=0, b;\n"
" if (x) { }\n"
" else if (y==2) { a=1; b=2; }\n"
" if (a) { ++b; }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// asm
checkUninitVar2("void f() {\n"
" int x;\n"