diff --git a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp index 2d2acd9d44..172a3697e4 100644 --- a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp +++ b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.cpp @@ -816,7 +816,11 @@ namespace AZ::SettingsRegistryMergeUtils } } - void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, const AZ::CommandLine& commandLine, bool executeCommands) + // This function intentionally copies `commandLine`. It looks like it only uses it as a const reference, but the + // code in the loop makes calls that mutates the `commandLine` instance, invalidating the iterators. Making a copy + // ensures that the iterators remain valid. + // NOLINTNEXTLINE(performance-unnecessary-value-param) + void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, AZ::CommandLine commandLine, bool executeCommands) { // Iterate over all the command line options in order to parse the --regset and --regremove // arguments in the order they were supplied @@ -831,7 +835,7 @@ namespace AZ::SettingsRegistryMergeUtils continue; } } - if (commandArgument.m_option == "regremove") + else if (commandArgument.m_option == "regremove") { if (!registry.Remove(commandArgument.m_value)) { diff --git a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.h b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.h index b482530d24..dbeb1bfe24 100644 --- a/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.h +++ b/Code/Framework/AzCore/AzCore/Settings/SettingsRegistryMergeUtils.h @@ -15,11 +15,7 @@ #include #include #include - -namespace AZ -{ - class CommandLine; -} +#include namespace AZ::IO { @@ -217,7 +213,7 @@ namespace AZ::SettingsRegistryMergeUtils //! example: --regdump /My/Array/With/Objects //! --regdumpall Dumps the entire settings registry to output. //! Note that this function is only called in development builds and is compiled out in release builds. - void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, const AZ::CommandLine& commandLine, bool executeCommands); + void MergeSettingsToRegistry_CommandLine(SettingsRegistryInterface& registry, AZ::CommandLine commandLine, bool executeCommands); //! Stores the command line settings into the Setting Registry //! The arguments can be used later anywhere the command line is needed