1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0031320: TObj - method TObj_Object::GetFatherObject() is not protected against deleted object

This commit is contained in:
mpv 2020-08-31 18:24:59 +03:00 committed by bugmaster
parent f5e758d239
commit 17a5b56767
4 changed files with 85 additions and 1 deletions

View 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;
}

View File

@ -33,6 +33,7 @@ TKXDESTEP
TKXSDRAW
TKSTL
TKXml
TKTObj
CSF_gdi32
CSF_advapi32
CSF_user32

View 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 ))

13
tests/bugs/caf/bug31320 Normal file
View File

@ -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