]> OCCT Git - occt-copy.git/commitdiff
0026461: STEP Import interface crashes
authorika <ika@opencascade.com>
Thu, 20 Aug 2015 15:10:23 +0000 (18:10 +0300)
committerabv <abv@opencascade.com>
Wed, 2 Sep 2015 11:39:29 +0000 (14:39 +0300)
Add a check for NULL;
some code refactoring.

src/STEPCAFControl/STEPCAFControl_Reader.cxx
tests/bugs/step/bug26461 [new file with mode: 0644]

index 5230ac66bcba0d4ae96287b29a8a4e4b5679b6d0..6653659e7acf7622a9f73d0530b9da7c66330d20 100644 (file)
@@ -1032,9 +1032,9 @@ TDF_Label STEPCAFControl_Reader::FindInstance (const Handle(StepRepr_NextAssembl
 //=======================================================================
 
 Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSession) &WS,
-                                                  Handle(TDocStd_Document)& Doc,
-                                                  const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
-                                                  const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
+                                                   Handle(TDocStd_Document)& Doc,
+                                                   const STEPCAFControl_DataMapOfPDExternFile &PDFileMap,
+                                                   const XCAFDoc_DataMapOfShapeLabel &ShapeLabelMap) const
 {
   // get starting data
   Handle(Interface_InterfaceModel) Model = WS->Model();
@@ -1057,7 +1057,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
     if ( enti->DynamicType() == tNAUO ) {
       L.Nullify();
       Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO = 
-       Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
+        Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(enti);
       if(NAUO.IsNull()) continue;
       Interface_EntityIterator subs = WS->Graph().Sharings(NAUO);
       for (subs.Start(); subs.More(); subs.Next()) {
@@ -1083,12 +1083,17 @@ Standard_Boolean STEPCAFControl_Reader::ReadNames (const Handle(XSControl_WorkSe
     if ( enti->DynamicType() == tPD ) {
       L.Nullify();
       Handle(StepBasic_ProductDefinition) PD = 
-       Handle(StepBasic_ProductDefinition)::DownCast(enti);
+        Handle(StepBasic_ProductDefinition)::DownCast(enti);
       if(PD.IsNull()) continue;
-      Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
-      if(!Prod->Name().IsNull() && Prod->Name()->UsefullLength()>0) name = Prod->Name();
-      else if (!Prod->Id().IsNull()) name = Prod->Id();
-      else name = new TCollection_HAsciiString;
+      Handle(StepBasic_Product) Prod = (!PD->Formation().IsNull() ? PD->Formation()->OfProduct() : NULL);
+      if (Prod.IsNull())
+        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 );
       if ( L.IsNull() ) continue;
       TCollection_ExtendedString str ( name->String() );
diff --git a/tests/bugs/step/bug26461 b/tests/bugs/step/bug26461
new file mode 100644 (file)
index 0000000..caa6373
--- /dev/null
@@ -0,0 +1,11 @@
+puts "============"
+puts "OCC26461"
+puts "============"
+puts ""
+#####################################################
+# STEP Import interface crashes
+#####################################################
+
+ReadStep D [locate_data_file bug26461_test_ap227.stp]
+
+