From babd17232818e58cf35f9783809e16ffe80fdc7e Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 7 Nov 2012 11:00:03 +0100 Subject: [PATCH] Fix crash when accessing non-existent sub-element in TopoShape --- src/Mod/Part/App/TopoShape.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 1d50d9b13..68c731fdc 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -370,18 +370,27 @@ TopoDS_Shape TopoShape::getSubShape(const char* Type) const int index=std::atoi(&shapetype[4]); TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(this->_Shape, TopAbs_FACE, anIndices); + // To avoid a segmentation fault we have to check if container is empty + if (anIndices.IsEmpty()) + Standard_Failure::Raise("Shape has no faces"); return anIndices.FindKey(index); } else if (shapetype.size() > 4 && shapetype.substr(0,4) == "Edge") { int index=std::atoi(&shapetype[4]); TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(this->_Shape, TopAbs_EDGE, anIndices); + // To avoid a segmentation fault we have to check if container is empty + if (anIndices.IsEmpty()) + Standard_Failure::Raise("Shape has no edges"); return anIndices.FindKey(index); } else if (shapetype.size() > 6 && shapetype.substr(0,6) == "Vertex") { int index=std::atoi(&shapetype[6]); TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(this->_Shape, TopAbs_VERTEX, anIndices); + // To avoid a segmentation fault we have to check if container is empty + if (anIndices.IsEmpty()) + Standard_Failure::Raise("Shape has no vertexes"); return anIndices.FindKey(index); }