From 22be76c8269f317e2fbe2ce1fddf1fb2b443c8ce Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 1 Mar 2024 21:05:15 +0000 Subject: Identifier string_view invalidation fix --- src/openvic-simulation/types/IdentifierRegistry.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index f1edc95..3c81cfc 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -193,8 +193,13 @@ namespace OpenVic { return duplicate_callback(name, new_identifier); } + /* This string must be created before item is moved as that can invalidate new_identifier. */ + std::string new_identifier_str { new_identifier }; + items.emplace_back(std::move(item)); - identifier_index_map.emplace(std::move(new_identifier), StorageInfo::get_back_index(items)); + + identifier_index_map.emplace(std::move(new_identifier_str), StorageInfo::get_back_index(items)); + return true; } -- cgit v1.2.3-56-ga3b1