From d8b25da73c0a5586336761af5f1a4884298c8b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 25 Nov 2013 06:38:23 +0100 Subject: [PATCH] Fixed #4740 (False Positive: Uninitialised variable 'int *a[2][19]; int **b = a[0];') --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ebdf008db..0708e2bcf 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -413,7 +413,7 @@ private: // Variable declaration.. if (tok.varId() && Token::Match(&tok, "%var% [[;]")) { const Variable* var2 = tok.variable(); - if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isExtern() && !var2->isConst()) { + if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isExtern() && !var2->isConst() && !Token::simpleMatch(tok.linkAt(1), "] [")) { if (tok.linkAt(1)) { // array const Token* endtok = tok.next(); while (endtok->link()) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 78aadc953..58a387747 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1305,6 +1305,13 @@ private: " return a[0][1];\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", "", errout.str()); + + // # 4740 + checkUninitVar("void f() {\n" + " int *a[2][19];\n" + " int **b = a[0];\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // alloc..