uninitvar: fixed TODO assertion

This commit is contained in:
Daniel Marjamäki 2021-05-14 11:54:18 +02:00
parent 56bc5536aa
commit c29997b117
2 changed files with 13 additions and 1 deletions

View File

@ -1029,6 +1029,18 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
if (possibleParent && isLikelyStreamRead(mTokenizer->isCPP(), possibleParent)) if (possibleParent && isLikelyStreamRead(mTokenizer->isCPP(), possibleParent))
return false; 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 (Token::Match(possibleParent, "[(,]")) {
if (unknown) if (unknown)
return false; // TODO: output some info message? return false; // TODO: output some info message?

View File

@ -1487,7 +1487,7 @@ private:
" int a[10];\n" " int a[10];\n"
" f(a[0]);\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 // Ticket #2320
checkUninitVar("void foo() {\n" checkUninitVar("void foo() {\n"