Commit d7bbfa41 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'fix-read-after-free'

5b2c2d2f Merge branch 'backport-fix-read-after-free' into fix-read-after-free
23ffb72a cmake: Fix read-after-free while checking command-line arguments
fe44f057 cmake: Fix read-after-free while checking command-line arguments
parents 38befe39 5b2c2d2f
...@@ -343,16 +343,24 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) ...@@ -343,16 +343,24 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
// The value is transformed if it is a filepath for example, so // The value is transformed if it is a filepath for example, so
// we can't compare whether the value is already in the cache until // we can't compare whether the value is already in the cache until
// after we call AddCacheEntry. // after we call AddCacheEntry.
const char *cachedValue = bool haveValue = false;
this->CacheManager->GetCacheValue(var); std::string cachedValue;
if(this->WarnUnusedCli)
{
if(const char *v = this->CacheManager->GetCacheValue(var))
{
haveValue = true;
cachedValue = v;
}
}
this->CacheManager->AddCacheEntry(var, value.c_str(), this->CacheManager->AddCacheEntry(var, value.c_str(),
"No help, variable specified on the command line.", type); "No help, variable specified on the command line.", type);
if(this->WarnUnusedCli) if(this->WarnUnusedCli)
{ {
if (!cachedValue if (!haveValue ||
|| strcmp(this->CacheManager->GetCacheValue(var), cachedValue != this->CacheManager->GetCacheValue(var))
cachedValue) != 0)
{ {
this->WatchUnusedCli(var); this->WatchUnusedCli(var);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment