Skip to content

Commit

Permalink
programmemory.cpp: avoid usage of non-const ProgramMemory::begin()
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jul 31, 2024
1 parent 53e55be commit ce3f655
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,12 @@ ProgramMemoryState::ProgramMemoryState(const Settings* s) : settings(s)
void ProgramMemoryState::replace(ProgramMemory pm, const Token* origin)
{
if (origin)
for (const auto& p : pm)
{
// use const object otherwise it will call the non-const begin()
const auto& pm2 = pm;
for (const auto& p : pm2)
origins[p.first.getExpressionId()] = origin;
}
state.replace(std::move(pm));
}

Expand Down Expand Up @@ -1370,7 +1374,9 @@ namespace {
if (!sortConditions(conditions1))
return unknown();

for (const auto& p : *pm) {
// use const object otherwise it will call the non-const begin()
const auto& pm2 = *pm;
for (const auto& p : pm2) {
const Token* tok = p.first.tok;
if (!tok)
continue;
Expand Down

0 comments on commit ce3f655

Please sign in to comment.