Skip to content

Commit

Permalink
programmemory.cpp: avoid calls to non-const at()
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jul 31, 2024
1 parent 53e55be commit 199f4a5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,8 @@ namespace {
ValueFlow::Value executeMultiCondition(bool b, const Token* expr)
{
if (pm->hasValue(expr->exprId())) {
const ValueFlow::Value& v = pm->at(expr->exprId());
const auto& pm2 = *pm;
const ValueFlow::Value& v = pm2.at(expr->exprId());
if (v.isIntValue())
return v;
}
Expand Down Expand Up @@ -1577,7 +1578,8 @@ namespace {
return execute(expr->astOperand1());
}
if (expr->exprId() > 0 && pm->hasValue(expr->exprId())) {
ValueFlow::Value result = pm->at(expr->exprId());
const ProgramMemory& pm2 = *pm;
ValueFlow::Value result = pm2.at(expr->exprId());
if (result.isImpossible() && result.isIntValue() && result.intvalue == 0 && isUsedAsBool(expr, *settings)) {
result.intvalue = !result.intvalue;
result.setKnown();
Expand Down Expand Up @@ -1693,7 +1695,8 @@ namespace {
if (!expr)
return v;
if (expr->exprId() > 0 && pm->hasValue(expr->exprId())) {
if (updateValue(v, pm->at(expr->exprId())))
const auto& pm2 = *pm;
if (updateValue(v, pm2.at(expr->exprId())))
return v;
}
// Find symbolic values
Expand All @@ -1704,7 +1707,8 @@ namespace {
continue;
if (value.tokvalue->exprId() > 0 && !pm->hasValue(value.tokvalue->exprId()))
continue;
ValueFlow::Value v2 = pm->at(value.tokvalue->exprId());
const auto& pm2 = *pm;
ValueFlow::Value v2 = pm2.at(value.tokvalue->exprId());
if (!v2.isIntValue() && value.intvalue != 0)
continue;
v2.intvalue += value.intvalue;
Expand Down

0 comments on commit 199f4a5

Please sign in to comment.