From c29997b1175e6edad61167d36c22b016e0156c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 14 May 2021 11:54:18 +0200 Subject: [PATCH] uninitvar: fixed TODO assertion --- lib/checkuninitvar.cpp | 12 ++++++++++++ test/testuninitvar.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 66e72040f..522d40017 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1029,6 +1029,18 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al if (possibleParent && isLikelyStreamRead(mTokenizer->isCPP(), possibleParent)) return false; } + if (alloc == ARRAY && Token::simpleMatch(vartok->astParent(), "[")) { + const Token *arrayValue = vartok; + while (arrayValue->astParent() && + (Token::simpleMatch(arrayValue->astParent(), "[") || arrayValue->astParent()->isUnaryOp("*")) && + arrayValue == arrayValue->astParent()->astOperand1()) + arrayValue = arrayValue->astParent(); + if (Token::Match(arrayValue->astParent(), "[(,]")) { + const int use = isFunctionParUsage(arrayValue, pointer, NO_ALLOC, indirect); + if (use >= 0) + return (use>0); + } + } if (Token::Match(possibleParent, "[(,]")) { if (unknown) return false; // TODO: output some info message? diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 41bd1d782..3e7d99b16 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1487,7 +1487,7 @@ private: " int a[10];\n" " f(a[0]);\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Uninitialized variable: a\n", "", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout.str()); // Ticket #2320 checkUninitVar("void foo() {\n"