Reuse isVariableChanged() in auto variables
This commit is contained in:
parent
cde63c7573
commit
d0819e4792
|
@ -206,19 +206,14 @@ void CheckAutoVariables::assignFunctionArg()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool reassignedGlobalPointer(const Token *vartok, unsigned int pointerVarId)
|
static bool reassignedGlobalPointer(const Token *vartok, unsigned int pointerVarId, const Settings *settings, bool cpp)
|
||||||
{
|
{
|
||||||
const Token * const end = vartok->variable()->typeStartToken()->scope()->bodyEnd;
|
return isVariableChanged(vartok,
|
||||||
for (const Token *tok2 = vartok; tok2 != nullptr && tok2 != end; tok2 = tok2->next()) {
|
vartok->variable()->scope()->bodyEnd,
|
||||||
if (Token::Match(tok2, "%varid% =", pointerVarId))
|
pointerVarId,
|
||||||
return true;
|
true,
|
||||||
if (Token::Match(tok2, "%name% (") && !Token::simpleMatch(tok2->linkAt(1), ") {")) {
|
settings,
|
||||||
// Bailout: possibly written
|
cpp);
|
||||||
// TODO: check if it is written
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,11 +234,11 @@ void CheckAutoVariables::autoVariables()
|
||||||
const Token * const pointer = tok->next();
|
const Token * const pointer = tok->next();
|
||||||
if (isAutoVarArray(tok->tokAt(3))) {
|
if (isAutoVarArray(tok->tokAt(3))) {
|
||||||
const Token * const array = tok->tokAt(3);
|
const Token * const array = tok->tokAt(3);
|
||||||
if (!reassignedGlobalPointer(array, pointer->varId()))
|
if (!reassignedGlobalPointer(array, pointer->varId(), mSettings, mTokenizer->isCPP()))
|
||||||
errorAssignAddressOfLocalArrayToGlobalPointer(pointer, array);
|
errorAssignAddressOfLocalArrayToGlobalPointer(pointer, array);
|
||||||
} else if (isAutoVar(tok->tokAt(4))) {
|
} else if (isAutoVar(tok->tokAt(4))) {
|
||||||
const Token * const variable = tok->tokAt(4);
|
const Token * const variable = tok->tokAt(4);
|
||||||
if (!reassignedGlobalPointer(variable, pointer->varId()))
|
if (!reassignedGlobalPointer(variable, pointer->varId(), mSettings, mTokenizer->isCPP()))
|
||||||
errorAssignAddressOfLocalVariableToGlobalPointer(pointer, variable);
|
errorAssignAddressOfLocalVariableToGlobalPointer(pointer, variable);
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "[;{}] %var% . %var% = & %var%")) {
|
} else if (Token::Match(tok, "[;{}] %var% . %var% = & %var%")) {
|
||||||
|
|
Loading…
Reference in New Issue