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..
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
@ -1353,7 +1364,7 @@ private:
|
|||
"{\n"
|
||||
" int* p;\n"
|
||||
" while (*p != 8) {\n" // <<
|
||||
" *p = 7;\n"
|
||||
" *p = 7;\n"
|
||||
" p = new int(9);\n"
|
||||
" }\n"
|
||||
"}");
|
||||
|
|
Loading…
Reference in New Issue