Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Dec 2, 2023
1 parent e6b9173 commit 31ff79f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,8 @@ namespace {

explicit Executor(ProgramMemory* pm = nullptr, const Settings* settings = nullptr) : pm(pm), settings(settings) {}

std::unordered_map<nonneg int, ValueFlow::Value> executeAll(const std::vector<const Token*>& toks, bool* b = nullptr) const
std::unordered_map<nonneg int, ValueFlow::Value> executeAll(const std::vector<const Token*>& toks,
bool* b = nullptr) const
{
std::unordered_map<nonneg int, ValueFlow::Value> result;
auto state = *this;
Expand All @@ -1269,7 +1270,7 @@ namespace {
continue;
result.insert(std::make_pair(tok->exprId(), r));
// Short-circuit evaluation
if(b && isTrueOrFalse(r, *b))
if (b && isTrueOrFalse(r, *b))
break;
}
return result;
Expand Down Expand Up @@ -1298,7 +1299,8 @@ namespace {
}

// Evaluate recursively if there are no exprids
if((expr->astOperand1() && expr->astOperand1()->exprId() == 0) || (expr->astOperand2() && expr->astOperand2()->exprId() == 0)) {
if ((expr->astOperand1() && expr->astOperand1()->exprId() == 0) ||
(expr->astOperand2() && expr->astOperand2()->exprId() == 0)) {
ValueFlow::Value lhs = execute(expr->astOperand1());
if (isTrueOrFalse(lhs, b))
return lhs;
Expand All @@ -1314,7 +1316,7 @@ namespace {
if (n > 50)
return unknown;
std::vector<const Token*> conditions1 = flattenConditions(expr);
if(conditions1.empty())
if (conditions1.empty())
return unknown;
std::unordered_map<nonneg int, ValueFlow::Value> condValues = executeAll(conditions1, &b);
bool allNegated = true;
Expand All @@ -1323,15 +1325,16 @@ namespace {
const ValueFlow::Value& v = p.second;
if (isTrueOrFalse(v, b))
return v;
allNegated &= isTrueOrFalse(v, !b);;
if(allNegated && negatedValue.isUninitValue())
allNegated &= isTrueOrFalse(v, !b);
;
if (allNegated && negatedValue.isUninitValue())
negatedValue = v;
}
if (condValues.size() == conditions1.size() && allNegated)
return negatedValue;
if (n > 4)
return unknown;
if(!sortConditions(conditions1))
if (!sortConditions(conditions1))
return unknown;

for (const auto& p : *pm) {
Expand All @@ -1343,7 +1346,7 @@ namespace {
if (n != astCount(tok, expr->str().c_str()))
continue;
std::vector<const Token*> conditions2 = flattenConditions(tok);
if(!sortConditions(conditions2))
if (!sortConditions(conditions2))
return unknown;
if (conditions1.size() == conditions2.size() &&
std::equal(conditions1.begin(), conditions1.end(), conditions2.begin(), &TokenExprIdEqual))
Expand Down

0 comments on commit 31ff79f

Please sign in to comment.