From 8dc54d3c62c90e37d6f46e86a256271bd3aa26f1 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 10 Mar 2023 13:20:03 +0100 Subject: [PATCH] Add a reserve before to copy attribute (to solve a bug for index versions) --- .../include/CGAL/Combinatorial_map_storages_with_index.h | 7 +++++++ .../include/CGAL/Generalized_map_storages_with_index.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h b/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h index 5b4bfbc0f7a..584442412c5 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h @@ -288,6 +288,13 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "copy_attribute called but i-attributes are disabled."); + // We need to do a reserve before the emplace in order to avoid a bug of + // invalid reference when the container is reallocated. + std::get::value> + (mattribute_containers).reserve + (std::get::value> + (mattribute_containers).size()+1); + typename Attribute_descriptor::type res= std::get::value> (mattribute_containers).emplace(get_attribute(ah)); diff --git a/Generalized_map/include/CGAL/Generalized_map_storages_with_index.h b/Generalized_map/include/CGAL/Generalized_map_storages_with_index.h index 80044bdc7d3..828004b8416 100644 --- a/Generalized_map/include/CGAL/Generalized_map_storages_with_index.h +++ b/Generalized_map/include/CGAL/Generalized_map_storages_with_index.h @@ -242,6 +242,13 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "copy_attribute called but i-attributes are disabled."); + // We need to do a reserve before the emplace in order to avoid a bug of + // invalid reference when the container is reallocated. + std::get::value> + (mattribute_containers).reserve + (std::get::value> + (mattribute_containers).size()+1); + typename Attribute_descriptor::type res= std::get::value> (mattribute_containers).emplace(get_attribute(ah));