From d907bcc454b0cd6a5a32a7a831cf4eaed83d934f Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 22 Jun 2012 18:23:12 -0700 Subject: [PATCH] Fix bug with adding invalid mwm file to maps container in MwmSet. --- indexer/mwm_set.cpp | 23 ++++++++++++++++------- indexer/mwm_set.hpp | 14 ++++++++------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/indexer/mwm_set.cpp b/indexer/mwm_set.cpp index e239bfed67..8d763e08a8 100644 --- a/indexer/mwm_set.cpp +++ b/indexer/mwm_set.cpp @@ -23,6 +23,12 @@ namespace }; } // unnamed namespace +MwmInfo::MwmInfo() : m_lockCount(0), m_status(STATUS_REMOVED) +{ + // Important: STATUS_REMOVED - is the default value. + // Apply STATUS_ACTIVE before adding to maps container. +} + MwmSet::MwmLock::MwmLock(MwmSet const & mwmSet, MwmId mwmId) : m_mwmSet(mwmSet), m_id(mwmId), m_pValue(mwmSet.LockValue(mwmId)) { @@ -84,9 +90,8 @@ MwmSet::MwmId MwmSet::GetFreeId() if (m_info[i].m_status == MwmInfo::STATUS_REMOVED) return i; } + m_info.push_back(MwmInfo()); - m_info.back().m_status = MwmInfo::STATUS_REMOVED; - m_info.back().m_lockCount = 0; m_name.push_back(string()); return size; } @@ -123,14 +128,18 @@ int MwmSet::Add(string const & fileName, m2::RectD & r) return -1; } + // this function can throw an exception for bad mwm file + MwmInfo info; + int const version = GetInfo(fileName, info); + + info.m_status = MwmInfo::STATUS_ACTIVE; + MwmId const id = GetFreeId(); m_name[id] = fileName; - memset(&m_info[id], 0, sizeof(MwmInfo)); - int const version = GetInfo(fileName, m_info[id]); - m_info[id].m_lockCount = 0; - m_info[id].m_status = MwmInfo::STATUS_ACTIVE; + m_info[id] = info; - r = m_info[id].m_limitRect; + r = info.m_limitRect; + ASSERT ( r.IsValid(), () ); return version; } diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index 489fdceb2d..00235b7604 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -9,13 +9,15 @@ #include "../std/vector.hpp" -// Information about stored mwm. +/// Information about stored mwm. class MwmInfo { public: - m2::RectD m_limitRect; // Limit rect of mwm. - uint8_t m_minScale; // Min zoom level of mwm. - uint8_t m_maxScale; // Max zoom level of mwm. + MwmInfo(); + + m2::RectD m_limitRect; ///< Limit rect of mwm. + uint8_t m_minScale; ///< Min zoom level of mwm. + uint8_t m_maxScale; ///< Max zoom level of mwm. // Does this MwmInfo represent a valid Mwm? inline bool isValid() const { return (m_status == STATUS_ACTIVE); } @@ -25,8 +27,8 @@ private: friend class MwmSet; enum Status { STATUS_ACTIVE = 0, STATUS_TO_REMOVE = 1, STATUS_REMOVED = 2 }; - uint8_t m_lockCount; // Number of locks. - uint8_t m_status; // + uint8_t m_lockCount; ///< Number of locks. + uint8_t m_status; ///< Current country status. }; class MwmSet