From 3e70ecfa80f94689e5917e18ac861adef4a1840f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 24 Nov 2024 22:31:38 +0100 Subject: [PATCH] Avoid comparing iterators that could have been invalidated after erase() --- include/boost/container/detail/flat_tree.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index d7a45f9c..a753a456 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -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);