From c76f44a8b3c2d5e5e5fbf1f45dedb761f1040abf Mon Sep 17 00:00:00 2001 From: joaquintides Date: Tue, 18 Oct 2022 16:18:05 +0200 Subject: [PATCH] hardened unchecked_rehash against exceptions thrown in the middle of value move construction --- include/boost/unordered/detail/foa.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 0de4782c..827c22c2 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1627,8 +1627,11 @@ private: std::size_t num_tx=0; BOOST_TRY{ for_all_elements([&,this](value_type* p){ - nosize_transfer_element(p,new_arrays_); + /* We increment num_tx *before* actual transfer to guard us against + * exceptions thrown in the middle of value move construction. + */ ++num_tx; + nosize_transfer_element(p,new_arrays_); }); } BOOST_CATCH(...){