uninitialized variables; fix false positive in loop
This commit is contained in:
parent
eb96e4980e
commit
899b88754f
|
@ -858,9 +858,11 @@ const Token* CheckUninitVar::checkLoopBodyRecursive(const Token *start, const Va
|
|||
|
||||
if (tok->str() == "{") {
|
||||
const Token *errorToken1 = checkLoopBodyRecursive(tok, var, alloc, membervar, bailout);
|
||||
if (Token::simpleMatch(tok->link(), "} else {")) {
|
||||
const Token *elseBody = tok->link()->tokAt(2);
|
||||
tok = tok->link();
|
||||
if (Token::simpleMatch(tok, "} else {")) {
|
||||
const Token *elseBody = tok->tokAt(2);
|
||||
const Token *errorToken2 = checkLoopBodyRecursive(elseBody, var, alloc, membervar, bailout);
|
||||
tok = elseBody->link();
|
||||
if (errorToken1 && errorToken2)
|
||||
return errorToken1;
|
||||
if (errorToken2)
|
||||
|
@ -868,7 +870,7 @@ const Token* CheckUninitVar::checkLoopBodyRecursive(const Token *start, const Va
|
|||
}
|
||||
if (bailout)
|
||||
return nullptr;
|
||||
if (errorToken1)
|
||||
if (!errorToken)
|
||||
errorToken = errorToken1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1303,6 +1303,20 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: nextEntry\n", errout.str());
|
||||
|
||||
checkUninitVar("void f(int x) {\n"
|
||||
" list *f = NULL;\n"
|
||||
" list *l;\n"
|
||||
"\n"
|
||||
" while (--x) {\n"
|
||||
" if (!f)\n"
|
||||
" f = c;\n"
|
||||
" else\n"
|
||||
" l->next = c;\n" // <- not uninitialized
|
||||
" l = c;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// switch..
|
||||
|
|
Loading…
Reference in New Issue