Commit e4440927 by Charles Beattie Committed by GitHub

and_condition_impl::combine_equal - Remove UB container modification. (#63)

* and_condition_impl::combine_equal - Remove UB container modification.

The container is modified while iterating it.
Switched to indexed based iteration to avoid UB.

* Update condition.cpp

Sorry missed this line.
parent a96b1e07
...@@ -115,27 +115,33 @@ namespace detail ...@@ -115,27 +115,33 @@ namespace detail
auto first = subs.front(); auto first = subs.front();
auto &fc = first->m_sub; auto &fc = first->m_sub;
for (auto c : fc) for (size_t fc_i = 0; fc_i < fc.size();)
{ {
if (not found_in_range(c, subs.begin() + 1, subs.end())) auto c = fc[fc_i];
if (not found_in_range(c, subs.begin() + 1, subs.end())) {
++fc_i;
continue; continue;
}
if (and_result == nullptr) if (and_result == nullptr)
and_result = new and_condition_impl(); and_result = new and_condition_impl();
and_result->m_sub.push_back(c); and_result->m_sub.push_back(c);
fc.erase(remove(fc.begin(), fc.end(), c), fc.end()); fc.erase(fc.begin() + fc_i);
for (auto sub : subs) for (auto sub : subs)
{ {
auto &ssub = sub->m_sub; auto &ssub = sub->m_sub;
for (auto sc : ssub) for (size_t ssub_i = 0; ssub_i < ssub.size();)
{ {
if (not sc->equals(c)) auto sc = ssub[ssub_i];
if (not sc->equals(c)) {
++ssub_i;
continue; continue;
}
ssub.erase(remove(ssub.begin(), ssub.end(), sc), ssub.end()); ssub.erase(ssub.begin() + ssub_i);
delete sc; delete sc;
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment