aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-03-01 22:05:15 +0100
committer hop311 <hop3114@gmail.com>2024-03-01 22:05:15 +0100
commit22be76c8269f317e2fbe2ce1fddf1fb2b443c8ce (patch)
tree8af0661815212aa60b4b311a1ca8ecbf184e6746 /src
parent164e76e367ff7dc5914f0d7105b5914fd3fba90a (diff)
Identifier string_view invalidation fixidentifier-name-fix
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp7
1 files changed, 6 insertions, 1 deletions
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;
}