Skip to content

Commit

Permalink
Avoid comparing iterators that could have been invalidated after erase()
Browse files Browse the repository at this point in the history
  • Loading branch information
igaztanaga committed Nov 24, 2024
1 parent a0848ce commit 3e70ecf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/boost/container/detail/flat_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,10 @@ class flat_tree
typename container_type::iterator const e = boost::movelib::inplace_set_unique_difference
(it, seq.end(), seq.begin(), it, val_cmp);

//it might be invalidated by erasing [e, seq.end) if e == it, so check it before
const bool remaining = e != it;
seq.erase(e, seq.cend());
//it might be invalidated by erasing [e, seq.end) if e == it
if (it != e)
if (remaining)
{
//Step 4: merge both ranges
(flat_tree_container_inplace_merge)(seq, it, this->priv_value_comp(), contiguous_tag);
Expand Down

0 comments on commit 3e70ecf

Please sign in to comment.