Fix Cppcheck warning
This commit is contained in:
parent
45a343ac2d
commit
0b3342abe5
|
@ -1863,13 +1863,10 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo
|
||||||
static void removeValues(std::list<ValueFlow::Value> &values, const std::list<ValueFlow::Value> &valuesToRemove)
|
static void removeValues(std::list<ValueFlow::Value> &values, const std::list<ValueFlow::Value> &valuesToRemove)
|
||||||
{
|
{
|
||||||
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end();) {
|
for (std::list<ValueFlow::Value>::iterator it = values.begin(); it != values.end();) {
|
||||||
bool found = false;
|
const bool found = std::any_of(valuesToRemove.cbegin(), valuesToRemove.cend(),
|
||||||
for (const ValueFlow::Value &v2 : valuesToRemove) {
|
[=](const ValueFlow::Value &v2) {
|
||||||
if (it->intvalue == v2.intvalue) {
|
return it->intvalue == v2.intvalue;
|
||||||
found = true;
|
});
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found)
|
if (found)
|
||||||
values.erase(it++);
|
values.erase(it++);
|
||||||
else
|
else
|
||||||
|
@ -1891,13 +1888,10 @@ static void valueFlowAST(Token *tok, unsigned int varid, const ValueFlow::Value
|
||||||
return;
|
return;
|
||||||
} else if (tok->str() == "||" && tok->astOperand1()) {
|
} else if (tok->str() == "||" && tok->astOperand1()) {
|
||||||
const std::list<ValueFlow::Value> &values = tok->astOperand1()->values();
|
const std::list<ValueFlow::Value> &values = tok->astOperand1()->values();
|
||||||
bool nonzero = false;
|
const bool nonzero = std::any_of(values.cbegin(), values.cend(),
|
||||||
for (const ValueFlow::Value &v : values) {
|
[=](const ValueFlow::Value &v) {
|
||||||
if (v.intvalue != 0) {
|
return v.intvalue != 0;
|
||||||
nonzero = true;
|
});
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!nonzero)
|
if (!nonzero)
|
||||||
return;
|
return;
|
||||||
ProgramMemory pm;
|
ProgramMemory pm;
|
||||||
|
@ -2075,16 +2069,14 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok2, "else {")) {
|
else if (Token::simpleMatch(tok2, "else {")) {
|
||||||
// Should scope be skipped because variable value is checked?
|
// Should scope be skipped because variable value is checked?
|
||||||
bool skipelse = false;
|
|
||||||
const Token *condition = tok2->linkAt(-1);
|
const Token *condition = tok2->linkAt(-1);
|
||||||
condition = condition ? condition->linkAt(-1) : nullptr;
|
condition = condition ? condition->linkAt(-1) : nullptr;
|
||||||
condition = condition ? condition->astOperand2() : nullptr;
|
condition = condition ? condition->astOperand2() : nullptr;
|
||||||
for (const ValueFlow::Value &v : values) {
|
|
||||||
if (conditionIsTrue(condition, getProgramMemory(tok2, varid, v))) {
|
const bool skipelse = std::any_of(values.cbegin(), values.cend(),
|
||||||
skipelse = true;
|
[=](const ValueFlow::Value &v) {
|
||||||
break;
|
return conditionIsTrue(condition, getProgramMemory(tok2, varid, v));
|
||||||
}
|
});
|
||||||
}
|
|
||||||
if (skipelse) {
|
if (skipelse) {
|
||||||
tok2 = tok2->linkAt(1);
|
tok2 = tok2->linkAt(1);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue