From 32bfe66b5d261bfc6c9f43f045f56651b8f012ea Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Sat, 2 Aug 2003 09:33:23 -0400 Subject: BUG: Fix problem with uninitialized variables --- Source/cmCacheManager.cxx | 24 ++++++++++++++++++++---- Source/cmCacheManager.h | 4 ++++ Source/cmMakefile.cxx | 3 ++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 4f272c9..a47bb22 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -247,6 +247,7 @@ bool cmCacheManager::LoadCache(const char* path, } else { + e.m_Initialized = true; m_Cache[entryKey] = e; } } @@ -363,7 +364,7 @@ bool cmCacheManager::SaveCache(const char* path) { const CacheEntry& ce = (*i).second; CacheEntryType t = ce.m_Type; - if(t == cmCacheManager::UNINITIALIZED) + if(t == cmCacheManager::UNINITIALIZED || !ce.m_Initialized) { /* // This should be added in, but is not for now. @@ -423,6 +424,11 @@ bool cmCacheManager::SaveCache(const char* path) for( cmCacheManager::CacheIterator i = this->NewIterator(); !i.IsAtEnd(); i.Next()) { + if ( !i.Initialized() ) + { + continue; + } + CacheEntryType t = i.GetType(); bool advanced = i.PropertyExists("ADVANCED"); if ( advanced ) @@ -581,7 +587,8 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char *key) const char* cmCacheManager::GetCacheValue(const char* key) const { CacheEntryMap::const_iterator i = m_Cache.find(key); - if(i != m_Cache.end() && i->second.m_Type != cmCacheManager::UNINITIALIZED) + if(i != m_Cache.end() && i->second.m_Type != cmCacheManager::UNINITIALIZED && + i->second.m_Initialized) { return i->second.m_Value.c_str(); } @@ -616,10 +623,11 @@ void cmCacheManager::AddCacheEntry(const char* key, if ( value ) { e.m_Value = value; + e.m_Initialized = true; } else { - e.m_Value = "(none)"; + e.m_Value = ""; } e.m_Type = type; // make sure we only use unix style paths @@ -682,7 +690,15 @@ void cmCacheManager::CacheIterator::SetValue(const char* value) return; } CacheEntry* entry = &this->GetEntry(); - entry->m_Value = value; + if ( value ) + { + entry->m_Value = value; + entry->m_Initialized = true; + } + else + { + entry->m_Value = ""; + } } const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 6655997..8ad7d44 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -39,6 +39,9 @@ private: std::string m_Value; CacheEntryType m_Type; std::map m_Properties; + bool m_Initialized; + CacheEntry() : m_Value(""), m_Type(UNINITIALIZED), m_Initialized(false) + {} }; public: @@ -59,6 +62,7 @@ public: const char* GetValue() const { return this->GetEntry().m_Value.c_str(); } void SetValue(const char*); CacheEntryType GetType() const { return this->GetEntry().m_Type; } + bool Initialized() { return this->GetEntry().m_Initialized; } cmCacheManager &m_Container; std::map::iterator m_Position; CacheIterator(cmCacheManager &cm) : m_Container(cm) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 36997c6..f61f7bf 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -842,7 +842,8 @@ void cmMakefile::AddCacheDefinition(const char* name, const char* value, const char* val = value; cmCacheManager::CacheIterator it = this->GetCacheManager()->GetCacheIterator(name); - if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED)) + if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) && + it.Initialized()) { val = it.GetValue(); } -- cgit v0.12