Refactor valueFlowUninit check (#3275)

This commit is contained in:
Paul Fultz II 2021-05-24 12:59:22 -05:00 committed by GitHub
parent c7be967769
commit 0862045ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 8 deletions

View File

@ -1522,20 +1522,14 @@ void CheckUninitVar::valueFlowUninit()
continue;
if (v->indirect > 1 || v->indirect < 0)
continue;
if (v->indirect == 0 && tok->valueType() && tok->valueType()->pointer == 0 && !isVariableUsage(tok, false, NO_ALLOC, 0))
continue;
bool uninitderef = false;
if (tok->variable()) {
bool unknown;
const bool isarray = !tok->variable() || tok->variable()->isArray();
const bool ispointer = astIsPointer(tok) && !isarray;
const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, mSettings);
if (ispointer && !deref) {
if (v->indirect >= 1)
if (ispointer && v->indirect == 1 && !deref)
continue;
if (!isVariableUsage(tok, true, NO_ALLOC, 0))
continue;
}
if (isarray && !deref)
continue;
uninitderef = deref && v->indirect == 0;
@ -1546,6 +1540,9 @@ void CheckUninitVar::valueFlowUninit()
if (!(Token::Match(tok->astParent(), ". %name% (") && uninitderef) &&
isVariableChanged(tok, v->indirect, mSettings, mTokenizer->isCPP()))
continue;
bool inconclusive = false;
if (isVariableChangedByFunctionCall(tok, v->indirect, mSettings, &inconclusive) || inconclusive)
continue;
uninitvarError(tok, tok->expressionString(), v->errorPath);
const Token* nextTok = nextAfterAstRightmostLeaf(parent);
if (nextTok == scope->bodyEnd)