Uninitialized variables; Fix false positive in switch inside loop
This commit is contained in:
parent
c70b8793a3
commit
abe810d718
|
@ -859,6 +859,12 @@ const Token* CheckUninitVar::checkLoopBodyRecursive(const Token *start, const Va
|
|||
}
|
||||
|
||||
if (tok->str() == "{") {
|
||||
// switch => bailout
|
||||
if (tok->scope() && tok->scope()->type == Scope::ScopeType::eSwitch) {
|
||||
bailout = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Token *errorToken1 = checkLoopBodyRecursive(tok, var, alloc, membervar, bailout);
|
||||
tok = tok->link();
|
||||
if (Token::simpleMatch(tok, "} else {")) {
|
||||
|
|
|
@ -1330,6 +1330,22 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// switch in loop
|
||||
checkUninitVar("int foo(int *p) {\n"
|
||||
" int x;\n"
|
||||
" while (true) {\n"
|
||||
" switch (*p) {\n"
|
||||
" case 1:\n"
|
||||
" return x;\n"
|
||||
" case 2:\n"
|
||||
" x = 123;\n"
|
||||
" break;\n"
|
||||
" };\n"
|
||||
" ++p\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// switch..
|
||||
|
|
Loading…
Reference in New Issue