Fixed #4740 (False Positive: Uninitialised variable 'int *a[2][19]; int **b = a[0];')

This commit is contained in:
Daniel Marjamäki 2013-11-25 06:38:23 +01:00
parent da540a3bb3
commit d8b25da73c
2 changed files with 8 additions and 1 deletions

View File

@ -413,7 +413,7 @@ private:
// Variable declaration.. // Variable declaration..
if (tok.varId() && Token::Match(&tok, "%var% [[;]")) { if (tok.varId() && Token::Match(&tok, "%var% [[;]")) {
const Variable* var2 = tok.variable(); 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 if (tok.linkAt(1)) { // array
const Token* endtok = tok.next(); const Token* endtok = tok.next();
while (endtok->link()) while (endtok->link())

View File

@ -1305,6 +1305,13 @@ private:
" return a[0][1];\n" " return a[0][1];\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", "", errout.str()); 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.. // alloc..