From f2e5fbd30ddcdb831af0c67477c1dde57777c1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 6 Jan 2015 07:44:04 +0100 Subject: [PATCH] Uninitialized variables: bailout when ({..}) are used to avoid fp. it can be handled better. --- lib/checkuninitvar.cpp | 5 +++++ lib/executionpath.cpp | 6 ++++++ test/testuninitvar.cpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 18cf8ff99..de80b8e66 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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; diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 890d7ca32..02fb32d61 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -145,6 +145,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list &che return; } + // ({ is not handled well + if (Token::simpleMatch(tok, "( {")) { + ExecutionPath::bailOut(checks); + return; + } + if (Token::simpleMatch(tok, "union {")) { tok = tok->next()->link(); continue; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b79026909..da83ec69d 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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"