]> OCCT Git - occt.git/commitdiff
0031320: TObj - method TObj_Object::GetFatherObject() is not protected against delete...
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 31 Aug 2020 15:24:59 +0000 (18:24 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 2 Sep 2020 16:42:39 +0000 (19:42 +0300)
src/QABugs/QABugs_20.cxx
src/TKQADraw/EXTERNLIB
src/TObj/TObj_Object.cxx
tests/bugs/caf/bug31320 [new file with mode: 0644]

index 6c8a9962a7f17cdf07a35187755de90a716f05c5..bc4f8d8d9218751e7d82e5ec548245a61f27a38b 100644 (file)
@@ -3519,6 +3519,70 @@ static Standard_Integer OCC31697(Draw_Interpretor& di, Standard_Integer argc, co
   return 0;
 }
 
+#include <TObj_Model.hxx>
+#include <TObj_TModel.hxx>
+#include <TObj_ObjectIterator.hxx>
+//=======================================================================
+//function :  OCC31320
+//purpose  : 
+//=======================================================================
+static Standard_Integer OCC31320(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+  if (argc < 3)
+  {
+    di << "Usage : " << argv[0] << " DocName ObjName\n";
+    return 1;
+  }
+  Handle(TObj_Model) aModel;
+  Handle(TDocStd_Document) D;
+  if (!DDocStd::GetDocument (argv[1], D)) 
+  {
+    di << "Error: document " << argv[1] << " not found\n";
+    return 1;
+  }
+
+  TDF_Label aLabel = D->Main();
+  Handle(TObj_TModel) aModelAttr;
+  if (!aLabel.IsNull() && aLabel.FindAttribute (TObj_TModel::GetID(), aModelAttr))
+    aModel = aModelAttr->Model();
+
+  if (aModel.IsNull())
+  {
+    di << "Error: TObj model " << argv[1] << " not found\n";
+    return 1;
+  }
+
+  Handle(TCollection_HExtendedString) aName = new TCollection_HExtendedString (argv[2]);
+  Handle(TObj_TNameContainer) aDict;
+  Handle(TObj_Object) anObj = aModel->FindObject (aName, aDict);
+
+  if (aModel.IsNull())
+  {
+    di << "Error: object " << argv[2] << " not found\n";
+    return 1;
+  }
+
+  // do a test: find the first child of an object, remove object and get the father of this child
+  Handle(TObj_ObjectIterator) aChildrenIter = anObj->GetChildren();
+  if (!aChildrenIter->More())
+  {
+    di << "Error: object " << argv[2] << " has no children\n";
+    return 1;
+  }
+
+  Handle(TObj_Object) aChild = aChildrenIter->Value();
+  anObj->Detach();
+  Handle(TObj_Object) aFather = aChild->GetFatherObject();
+  if (!aFather.IsNull())
+  {
+    di << "Error: father is not null\n";
+    return 1;
+  }
+
+  return 0;
+
+}
+
 void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
 
@@ -3587,5 +3651,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
 
   theCommands.Add("OCC31697", "OCC31697 expression variable", __FILE__, OCC31697, group);
 
+  theCommands.Add("OCC31320", "OCC31320 DocName ObjName : tests remove of the children GetFather method if father is removed", __FILE__, OCC31320, group);
+
   return;
 }
index bb588a05a2d3fee026c85fc4242b7ae2eaa65f80..816969b0026ae402e19ed2d5d1d12fbb05643eac 100755 (executable)
@@ -33,6 +33,7 @@ TKXDESTEP
 TKXSDRAW
 TKSTL
 TKXml
+TKTObj
 CSF_gdi32
 CSF_advapi32
 CSF_user32
index 2d4dde0b4c8e4ea8b63fd6aeb0b1ee50a3e459b3..eeef250f946c8d54702b2bf553c97dd6b0a07c31 100644 (file)
@@ -615,8 +615,12 @@ Standard_Boolean TObj_Object::GetObj(const TDF_Label& theLabel,
 Handle(TObj_Object) TObj_Object::GetFatherObject
                          (const Handle(Standard_Type)& theType) const
 {
-  Handle(TObj_Object) aFather, aSon(this);
+  Handle(TObj_Object) aFather;
 
+  if (myLabel.IsNull())
+    return aFather;
+
+  Handle(TObj_Object) aSon(this);
   while ( aSon->GetObj( aSon->GetLabel().Father(), aFather, Standard_True ) )
   {
     if (theType.IsNull() || aFather->IsKind( theType ))
diff --git a/tests/bugs/caf/bug31320 b/tests/bugs/caf/bug31320
new file mode 100644 (file)
index 0000000..ecceec5
--- /dev/null
@@ -0,0 +1,13 @@
+puts "============"
+puts "0031320: TObj - method TObj_Object::GetFatherObject() is not protected against deleted object"
+puts "============"
+puts ""
+
+pload TOBJ QAcommands
+
+# create document with object and sub-object
+TObjNew TD1
+TObjAddObj TD1 obj
+TObjAddChild TD1 obj subobj1
+
+OCC31320 TD1 obj