Avoid reading from a destroyed variable (#1347)
This code iterates over the items in a vector, and if one case is met, it mutates that same vector. This invalidates the object, as the place where that object used to be has been moved.
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
#include <AzCore/IO/Path/Path_fwd.h>
|
||||
#include <AzCore/Memory/OSAllocator.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class CommandLine;
|
||||
}
|
||||
#include <AzCore/Settings/CommandLine.h>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user