Uninitialized variable; Fixed FP after unconditional scope with conditional initialization

This commit is contained in:
Daniel Marjamäki 2021-05-20 18:38:59 +02:00
parent f1fff5e904
commit 8e650e4243
2 changed files with 19 additions and 2 deletions

View File

@ -383,9 +383,15 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
// Unconditional inner scope or try..
if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|try")) {
if (checkScopeForVariable(tok->next(), var, possibleInit, noreturn, alloc, membervar, variableValue))
bool possibleInitInner = false;
if (checkScopeForVariable(tok->next(), var, &possibleInitInner, noreturn, alloc, membervar, variableValue))
return true;
tok = tok->link();
if (possibleInitInner) {
number_of_if = 1;
if (possibleInit)
*possibleInit = true;
}
continue;
}

View File

@ -1069,6 +1069,17 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void foo(int *pix) {\n"
" int dest_x;\n"
" {\n"
" if (pix)\n"
" dest_x = 123;\n"
" }\n"
" if (pix)\n"
" a = dest_x;\n" // <- not uninitialized
"}");
ASSERT_EQUALS("", errout.str());
// ? :
checkUninitVar("static void foo(int v) {\n"
" int x;\n"