1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0026461: STEP Import interface crashes

Add a check for NULL;
some code refactoring.

Test case for issue CR26461
This commit is contained in:
ika 2015-08-27 13:30:38 +03:00 committed by ski
parent 649e34c9b6
commit 9c3cce7ab1
2 changed files with 25 additions and 9 deletions

View File

@ -1035,9 +1035,9 @@ TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssembl
//======================================================================= //=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS, Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
Handle(TDocStd_Document)& Doc, Handle(TDocStd_Document)& Doc,
const STEPCAFControl_DataMapOfPDExternFile &PDFileMap, const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
{ {
// get starting data // get starting data
Handle(Interface_InterfaceModel) Model = WS->Model(); Handle(Interface_InterfaceModel) Model = WS->Model();
@ -1060,7 +1060,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
if ( enti->DynamicType() == tNAUO ) { if ( enti->DynamicType() == tNAUO ) {
L.Nullify(); L.Nullify();
Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti); Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
if(NAUO.IsNull()) continue; if(NAUO.IsNull()) continue;
Interface_EntityIterator subs = WS->Graph().Sharings(NAUO); Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
for (subs.Start(); subs.More(); subs.Next()) { for (subs.Start(); subs.More(); subs.Next()) {
@ -1086,12 +1086,17 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
if ( enti->DynamicType() == tPD ) { if ( enti->DynamicType() == tPD ) {
L.Nullify(); L.Nullify();
Handle(StepBasic_ProductDefinition) PD = Handle(StepBasic_ProductDefinition) PD =
Handle(StepBasic_ProductDefinition)::DownCast(enti); Handle(StepBasic_ProductDefinition)::DownCast(enti);
if(PD.IsNull()) continue; if(PD.IsNull()) continue;
Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
if(!Prod->Name().IsNull() && Prod->Name()->UsefullLength()>0) name = Prod->Name(); if (Prod.IsNull())
else if (!Prod->Id().IsNull()) name = Prod->Id(); name = new TCollection_HAsciiString;
else name = new TCollection_HAsciiString; else if (!Prod->Name().IsNull() && Prod->Name()->UsefullLength() > 0)
name = Prod->Name();
else if (!Prod->Id().IsNull())
name = Prod->Id();
else
name = new TCollection_HAsciiString;
L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap ); L = GetLabelFromPD ( PD, STool, TP, PDFileMap, ShapeLabelMap );
if ( L.IsNull() ) continue; if ( L.IsNull() ) continue;
TCollection_ExtendedString str ( name->String() ); TCollection_ExtendedString str ( name->String() );

11
tests/bugs/step/bug26461 Normal file
View File

@ -0,0 +1,11 @@
puts "============"
puts "OCC26461"
puts "============"
puts ""
#####################################################
# STEP Import interface crashes
#####################################################
ReadStep D [locate_data_file bug26461_test_ap227.stp]