Skip to content

Commit f2e5fbd

Browse files
committed
Uninitialized variables: bailout when ({..}) are used to avoid fp. it can be handled better.
1 parent 1f698ca commit f2e5fbd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/checkuninitvar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
14241424
return true;
14251425
}
14261426

1427+
// bailout if there is ({
1428+
if (Token::simpleMatch(tok, "( {")) {
1429+
return true;
1430+
}
1431+
14271432
// bailout if there is assembler code
14281433
if (Token::simpleMatch(tok, "asm (")) {
14291434
return true;

lib/executionpath.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
145145
return;
146146
}
147147

148+
// ({ is not handled well
149+
if (Token::simpleMatch(tok, "( {")) {
150+
ExecutionPath::bailOut(checks);
151+
return;
152+
}
153+
148154
if (Token::simpleMatch(tok, "union {")) {
149155
tok = tok->next()->link();
150156
continue;

test/testuninitvar.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,20 @@ class TestUninitVar : public TestFixture {
905905
"}");
906906
ASSERT_EQUALS("", errout.str());
907907

908+
// ({ .. })
909+
{
910+
const char code[] = "void f() {\n"
911+
" int x;\n"
912+
" if (abc) { x = 123; }\n"
913+
" else { a = ({b=c;}); x = 456; }\n"
914+
" ++x;\n"
915+
"}";
916+
checkUninitVar(code);
917+
ASSERT_EQUALS("", errout.str());
918+
checkUninitVar2(code);
919+
ASSERT_EQUALS("", errout.str());
920+
}
921+
908922
// Ticket #3098 - False negative uninitialized variable
909923
checkUninitVar("void f()\n"
910924
"{\n"

0 commit comments

Comments
 (0)