Uninitialized variable; Fixed FP after unconditional scope with conditional initialization
This commit is contained in:
parent
f1fff5e904
commit
8e650e4243
|
@ -383,9 +383,15 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
|
|
||||||
// Unconditional inner scope or try..
|
// Unconditional inner scope or try..
|
||||||
if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|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;
|
return true;
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
if (possibleInitInner) {
|
||||||
|
number_of_if = 1;
|
||||||
|
if (possibleInit)
|
||||||
|
*possibleInit = true;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1069,6 +1069,17 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
checkUninitVar("static void foo(int v) {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue