diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2021-10-26 16:51:44 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2021-10-26 16:51:44 (GMT) |
commit | 69f95cf1d93945ace09ee9a87c0185b1ee6e4a47 (patch) | |
tree | ad62afb6d54b53c5326a471088caf03a5e19c7f3 /Source/CTest | |
parent | fb6ab54076217452e673ad310faba2a1a993366f (diff) | |
download | CMake-69f95cf1d93945ace09ee9a87c0185b1ee6e4a47.zip CMake-69f95cf1d93945ace09ee9a87c0185b1ee6e4a47.tar.gz CMake-69f95cf1d93945ace09ee9a87c0185b1ee6e4a47.tar.bz2 |
cmCTestRunTest: fix modifying non-existent envvars
When appending or modifying to a variable that has not been modified
before, the iterator was not valid, but it was used to insert into the
map again. Instead, just use indexing into the map since we know it will
exist by the end of the function anyways.
Fixes: #22796
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 20f0ed3..2d1562a 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -800,13 +800,9 @@ bool cmCTestRunTest::ForkProcess( auto apply_diff = [&env_application](const std::string& name, std::function<void(std::string&)> const& apply) { - auto entry = env_application.find(name); - std::string output; - if (entry != env_application.end() && entry->second) { - output = *entry->second; - } + std::string output = env_application[name].value_or(std::string{}); apply(output); - entry->second = output; + env_application[name] = output; }; bool err_occurred = false; |