Uninitialized variables: bailout when ({..}) are used to avoid fp. it can be handled better.

This commit is contained in:
Daniel Marjamäki 2015-01-06 07:44:04 +01:00
parent 1f698ca493
commit f2e5fbd30d
3 changed files with 25 additions and 0 deletions

View File

@ -1424,6 +1424,11 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
return true;
}
// bailout if there is ({
if (Token::simpleMatch(tok, "( {")) {
return true;
}
// bailout if there is assembler code
if (Token::simpleMatch(tok, "asm (")) {
return true;

View File

@ -145,6 +145,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
return;
}
// ({ is not handled well
if (Token::simpleMatch(tok, "( {")) {
ExecutionPath::bailOut(checks);
return;
}
if (Token::simpleMatch(tok, "union {")) {
tok = tok->next()->link();
continue;

View File

@ -905,6 +905,20 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// ({ .. })
{
const char code[] = "void f() {\n"
" int x;\n"
" if (abc) { x = 123; }\n"
" else { a = ({b=c;}); x = 456; }\n"
" ++x;\n"
"}";
checkUninitVar(code);
ASSERT_EQUALS("", errout.str());
checkUninitVar2(code);
ASSERT_EQUALS("", errout.str());
}
// Ticket #3098 - False negative uninitialized variable
checkUninitVar("void f()\n"
"{\n"