]> OCCT Git - occt.git/commitdiff
0018170: Modeling Data - crash in TopExp_Explorer::Init if Clear was called after...
authormsv <msv@opencascade.com>
Fri, 3 Sep 2021 13:11:35 +0000 (16:11 +0300)
committerkgv <kgv@opencascade.com>
Sun, 5 Sep 2021 20:13:27 +0000 (23:13 +0300)
TopExp_Explorer::Clear() now sets myTop=-1 with align to TopExp_Explorer::Init() logic.

src/TopExp/TopExp_Explorer.cxx
src/TopExp/TopExp_Explorer.hxx

index 569f5f21b1ccd0915b94d6cb7ffcc6da4953ac6b..d87dd372ed9ef80b85827d20a01113aaa85765c9 100644 (file)
@@ -33,49 +33,49 @@ static const Standard_Integer theStackSize = 20;
 
 //=======================================================================
 //function : TopExp_Explorer
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-TopExp_Explorer::TopExp_Explorer() :
-    myStack(0L),myTop(-1),hasMore(Standard_False)
+TopExp_Explorer::TopExp_Explorer()
+: myStack (0L),
+  myTop (-1),
+  mySizeOfStack (theStackSize),
+  toFind  (TopAbs_SHAPE),
+  toAvoid (TopAbs_SHAPE),
+  hasMore (Standard_False)
 {
   myStack = (TopoDS_Iterator*)Standard::Allocate(theStackSize*sizeof(TopoDS_Iterator));
-  mySizeOfStack = theStackSize;
 }
 
-
 //=======================================================================
 //function : TopExp_Explorer
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-TopExp_Explorer::TopExp_Explorer(const TopoDS_Shape& S, 
-                                const TopAbs_ShapeEnum ToFind, 
-                                const TopAbs_ShapeEnum ToAvoid):
-       myStack(0L),myTop(-1),hasMore(Standard_False)
-
+TopExp_Explorer::TopExp_Explorer (const TopoDS_Shape& theS,
+                                  const TopAbs_ShapeEnum theToFind,
+                                  const TopAbs_ShapeEnum theToAvoid)
+: myStack (0L),
+  myTop (-1),
+  mySizeOfStack (theStackSize),
+  toFind  (theToFind),
+  toAvoid (theToAvoid),
+  hasMore (Standard_False)
 {
   myStack = (TopoDS_Iterator*)Standard::Allocate(theStackSize*sizeof(TopoDS_Iterator));
-  mySizeOfStack = theStackSize;
-  Init(S,ToFind,ToAvoid);
+
+  Init (theS, theToFind, theToAvoid);
 }
 
 
 //=======================================================================
 //function : Init
-//purpose  : 
+//purpose  :
 //=======================================================================
-
 void  TopExp_Explorer::Init(const TopoDS_Shape& S, 
                            const TopAbs_ShapeEnum ToFind, 
                            const TopAbs_ShapeEnum ToAvoid)
 {
-  if(myTop >=0) {
-    for(int i=0;i<= myTop; i++)
-      myStack[i].~TopoDS_Iterator();
-  }
-  
-  myTop   = -1;
+  Clear();
+
   myShape = S;
   toFind  = ToFind;
   toAvoid = ToAvoid;
@@ -131,18 +131,11 @@ const TopoDS_Shape&  TopExp_Explorer::Current()const
     return myShape;
 }
 
-
 //=======================================================================
 //function : Next
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable: 4291) // to avoid warning when using new(buffer) syntax
-#endif
-
-void  TopExp_Explorer::Next()
+void TopExp_Explorer::Next()
 {
   Standard_Integer NewSize;
   TopoDS_Shape ShapTop;
@@ -219,28 +212,40 @@ void  TopExp_Explorer::Next()
   hasMore = Standard_False;
 }
 
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
 //=======================================================================
 //function : ReInit
-//purpose  : 
+//purpose  :
 //=======================================================================
-
-void  TopExp_Explorer::ReInit()
+void TopExp_Explorer::ReInit()
 {
   Init(myShape,toFind,toAvoid);
 }
 
-void  TopExp_Explorer::Destroy()
+//=======================================================================
+//function : ~TopExp_Explorer
+//purpose  :
+//=======================================================================
+TopExp_Explorer::~TopExp_Explorer()
 {
-  if (myStack) 
-    {
-      for(int i=0;i<= myTop; i++)myStack[i].~TopoDS_Iterator();
-      Standard::Free(myStack);
-    }
+  Clear();
+  if (myStack)
+  {
+    Standard::Free(myStack);
+  }
   mySizeOfStack = 0;
   myStack = 0L;
 }
 
+//=======================================================================
+//function : Clear
+//purpose  :
+//=======================================================================
+void TopExp_Explorer::Clear()
+{
+  hasMore = Standard_False;
+  for (int i = 0; i <= myTop; ++i)
+  {
+    myStack[i].~TopoDS_Iterator();
+  }
+  myTop = -1;
+}
index a49d3f15e7d8eb6953104a68d90cf9e5fc596587..bbdaba0d2e9f2530845552ed0612887c9bd7f588 100644 (file)
@@ -18,6 +18,7 @@
 #define _TopExp_Explorer_HeaderFile
 
 #include <TopExp_Stack.hxx>
+#include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
 
 //! An Explorer is a Tool to visit  a Topological Data
@@ -136,39 +137,21 @@ public:
 
   //! Clears the content of the explorer. It will return
   //! False on More().
-    void Clear();
-  
-  Standard_EXPORT void Destroy();
-~TopExp_Explorer()
-{
-  Destroy();
-}
+  Standard_EXPORT void Clear();
+
+  //! Destructor.
+  Standard_EXPORT ~TopExp_Explorer();
 
 private:
 
   TopExp_Stack myStack;
+  TopoDS_Shape myShape;
   Standard_Integer myTop;
   Standard_Integer mySizeOfStack;
-  TopoDS_Shape myShape;
-  Standard_Boolean hasMore;
   TopAbs_ShapeEnum toFind;
   TopAbs_ShapeEnum toAvoid;
+  Standard_Boolean hasMore;
 
 };
 
-#include <TopoDS_Iterator.hxx>
-
-inline void TopExp_Explorer::Clear()
-{
-  hasMore = Standard_False;
-  if (myTop > 0)
-  {
-    for (int i = 1; i <= myTop; i++)
-    {
-      myStack[i].~TopoDS_Iterator();
-    }
-  }
-  myTop = 0;
-}
-
 #endif // _TopExp_Explorer_HeaderFile