From 3d216a129cf449c158188d65ce7cf70d507b4238 Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 1 Mar 2024 21:45:53 +0000 Subject: Identifier string_view invalidation fix --- src/openvic-simulation/types/IdentifierRegistry.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index f1edc95..393ea37 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -194,7 +194,15 @@ namespace OpenVic { } items.emplace_back(std::move(item)); - identifier_index_map.emplace(std::move(new_identifier), StorageInfo::get_back_index(items)); + + const index_type index = StorageInfo::get_back_index(items); + + /* Get item's identifier via index rather than using new_identifier, as it may have been invalidated item's move. */ + identifier_index_map.emplace( + ValueInfo::get_identifier(ItemInfo::get_value(StorageInfo::get_item_from_index(items, index))), + StorageInfo::get_back_index(items) + ); + return true; } -- cgit v1.2.3-56-ga3b1