From b2aac0af7c57fcb642593fdf2314c569e415fc71 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 16 Apr 2019 20:56:30 +0300 Subject: [PATCH] [indexer][editor] crash fix for FeatureType which were created from EditableMapObjects --- indexer/feature.cpp | 12 ++++++++++-- indexer/feature_data.cpp | 4 ++-- indexer/feature_data.hpp | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/indexer/feature.cpp b/indexer/feature.cpp index 6babbbad26..f3acd0a870 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -196,21 +196,27 @@ FeatureType::FeatureType(SharedLoadInfo const * loadInfo, Buffer buffer) FeatureType::FeatureType(osm::MapObject const & emo) { - uint8_t const geomType = emo.GetGeomType(); + EHeaderTypeMask geomType = HEADER_GEOM_POINT; m_limitRect.MakeEmpty(); - switch (geomType) + switch (emo.GetGeomType()) { + case feature::GEOM_UNDEFINED: + // It is not possible because of FeatureType::GetFeatureType() never returns GEOM_UNDEFINED. + UNREACHABLE(); case feature::GEOM_POINT: + geomType = HEADER_GEOM_POINT; m_center = emo.GetMercator(); m_limitRect.Add(m_center); break; case feature::GEOM_LINE: + geomType = HEADER_GEOM_LINE; m_points = Points(emo.GetPoints().begin(), emo.GetPoints().end()); for (auto const & p : m_points) m_limitRect.Add(p); break; case feature::GEOM_AREA: + geomType = HEADER_GEOM_AREA; m_triangles = Points(emo.GetTriangesAsPoints().begin(), emo.GetTriangesAsPoints().end()); for (auto const & p : m_triangles) m_limitRect.Add(p); @@ -242,6 +248,8 @@ FeatureType::FeatureType(osm::MapObject const & emo) feature::EGeomType FeatureType::GetFeatureType() const { + // FeatureType::FeatureType(osm::MapObject const & emo) expects + // that GEOM_UNDEFINED is never be returned. switch (m_header & HEADER_GEOTYPE_MASK) { case HEADER_GEOM_LINE: return GEOM_LINE; diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index 0ba2844a2c..b40492f25d 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -131,7 +131,7 @@ private: namespace feature { -uint8_t CalculateHeader(size_t const typesCount, uint8_t const headerGeomType, +uint8_t CalculateHeader(size_t const typesCount, EHeaderTypeMask const headerGeomType, FeatureParamsBase const & params) { ASSERT(typesCount != 0, ("Feature should have at least one type.")); @@ -562,7 +562,7 @@ bool FeatureParams::CheckValid() const uint8_t FeatureParams::GetHeader() const { - return CalculateHeader(m_types.size(), GetTypeMask(), *this); + return CalculateHeader(m_types.size(), static_cast(GetTypeMask()), *this); } uint32_t FeatureParams::GetIndexForType(uint32_t t) diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index f69bb11b8a..66bb716c50 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -126,7 +126,7 @@ namespace feature std::string DebugPrint(TypesHolder const & holder); - uint8_t CalculateHeader(size_t const typesCount, uint8_t const headerGeomType, + uint8_t CalculateHeader(size_t const typesCount, EHeaderTypeMask const headerGeomType, FeatureParamsBase const & params); } // namespace feature