From 0966651a9c8d05f5a0b3668852f3c561b011233a Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 8 May 2023 09:37:46 -0500 Subject: [PATCH] GH-1062 Fix issue with variant internal variant_object being shared --- libraries/libfc/include/fc/variant_object.hpp | 10 ++++++++-- tests/trx_generator/trx_generator.cpp | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/libfc/include/fc/variant_object.hpp b/libraries/libfc/include/fc/variant_object.hpp index ee4b8550b5..12e5aeccd8 100644 --- a/libraries/libfc/include/fc/variant_object.hpp +++ b/libraries/libfc/include/fc/variant_object.hpp @@ -206,9 +206,15 @@ namespace fc ///@} + explicit mutable_variant_object( variant v ) + :_key_value( new std::vector() ) + { + *this = v.get_object(); + } + template>::value>> + typename = std::enable_if_t>::value && + !std::is_base_of>::value>> explicit mutable_variant_object( T&& v ) :_key_value( new std::vector() ) { diff --git a/tests/trx_generator/trx_generator.cpp b/tests/trx_generator/trx_generator.cpp index 2365bf6953..41f56ab79c 100644 --- a/tests/trx_generator/trx_generator.cpp +++ b/tests/trx_generator/trx_generator.cpp @@ -152,7 +152,7 @@ namespace eosio::testing { void update_key_word_fields_in_sub_action(const std::string& key, fc::mutable_variant_object& action_mvo, const std::string& action_inner_key, const std::string& key_word) { if (action_mvo.find(action_inner_key) != action_mvo.end()) { - auto inner = action_mvo[action_inner_key].get_object(); + const auto& inner = action_mvo[action_inner_key].get_object(); if (inner.find(key) != inner.end()) { fc::mutable_variant_object inner_mvo = fc::mutable_variant_object(inner); inner_mvo.set(key, key_word); @@ -235,7 +235,7 @@ namespace eosio::testing { const std::string gen_acct_name_per_trx("ACCT_PER_TRX"); - auto action_array = unpacked_actions_data_json.get_array(); + const auto& action_array = unpacked_actions_data_json.get_array(); _unpacked_actions.reserve(action_array.size()); std::transform(action_array.begin(), action_array.end(), std::back_inserter(_unpacked_actions), [&](const auto& var) {