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