26428: TNaming_Selector::Solve crash for empty named shape.
authorszy <szy@opencascade.com>
Thu, 24 Sep 2015 09:36:11 +0000 (12:36 +0300)
committerkgv <kgv@opencascade.com>
Thu, 24 Sep 2015 11:13:47 +0000 (14:13 +0300)
Test case for issue CR26428

src/DNaming/DNaming_BasicCommands.cxx
src/TNaming/TNaming_NamedShape.cxx
tests/bugs/caf/bug26428 [new file with mode: 0644]

index d5f0334..599ad7a 100644 (file)
@@ -465,7 +465,40 @@ static Standard_Integer DNaming_ImportShape (Draw_Interpretor& di,
   cout << "DNaming_NewShape : Error" << endl;
   return 1;  
 }
+//=======================================================================
+//function : CheckNSIter
+//purpose  : "CheckNSIter Doc  entry Shape new/old [1|0]"
+//=======================================================================
+
+static Standard_Integer CheckIter (Draw_Interpretor& di,
+                                 Standard_Integer nb, 
+                                 const char** arg) 
+{ 
+  if (nb > 3) { 
+    Handle(TDF_Data) aDF;
+       Standard_Boolean aNew(Standard_True);
+    if (!DDF::GetDF(arg[1],aDF)) return 1;
+       TDF_Label aLabel;
+       DDF::AddLabel(aDF, arg[2], aLabel);
+       TNaming_Builder aNB(aLabel);
+       const TopoDS_Shape& aShape = DBRep::Get(arg[3]);
+       aNB.Generated(aShape);
+       TNaming_Iterator aNameIter(aLabel);
+       if(nb == 5) aNew = (Standard_Boolean) atoi(arg[4]);
+       if(aNew) {
+         TNaming_NewShapeIterator aNewShapeIter(aNameIter); 
+         di << "DNaming_CheckIterator : New It is OK" << "\n";
+       } else {
+         TNaming_OldShapeIterator oldShapeIter(aNameIter); 
+         di << "DNaming_CheckIterator : Old It is OK" << "\n";
+       }
+       return 0;
+  } 
+  di << "DNaming_CheckIterator : Error" << "\n";
+  return 1;
+}
 
+//
 //=======================================================================
 //function : BasicCommands
 //purpose  : 
@@ -492,4 +525,6 @@ void  DNaming::BasicCommands(Draw_Interpretor& theCommands)
   theCommands.Add("Collect",     "Collect  df entry [onlymodif 0/1]",__FILE__,Collect ,        g);  
   theCommands.Add ("GeneratedShape", "Generatedshape df shape Generationentry [drawname]", __FILE__,Generatedshape,g);
   theCommands.Add("ImportShape", "ImportShape Doc Entry Shape [Name]",__FILE__,DNaming_ImportShape, g);  
+  //
+   theCommands.Add("CheckNSIter",    "CheckNSIter df entry shape new[1|0]",     __FILE__, CheckIter ,       g);  
 }
index 5246530..62ce577 100644 (file)
@@ -1015,10 +1015,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Standard_Integer            Trans,
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
-{
-  Standard_Boolean  Old = Standard_True;  
-  TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+{ 
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                    "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");  
+  TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);  
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_True); 
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1034,10 +1036,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 :myTrans(Trans)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {    
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1050,14 +1054,16 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1072,9 +1078,11 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {
-  Standard_Boolean  Old = Standard_True;  
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+   Standard_Boolean  Old(Standard_True);  
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1090,8 +1098,10 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    Standard_Boolean  Old(Standard_True);  
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
     SelectSameShape(myNode,Old,RS,myTrans);
   }
@@ -1105,7 +1115,8 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
   myNode = anIterator.myNode;
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
@@ -1113,6 +1124,7 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1124,9 +1136,9 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
 
 void TNaming_NewShapeIterator::Next() 
 {
-  Standard_Boolean  Old = Standard_True;
   TNaming_RefShape* RS  = myNode->myOld;
   myNode = myNode->NextSameShape(RS);
+  Standard_Boolean  Old(Standard_True);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1194,9 +1206,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
 {
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1213,9 +1227,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_False;
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");    
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1229,9 +1245,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {  
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1246,10 +1264,12 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 :myTrans(-1)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {  
-    Standard_Boolean  Old = Standard_False;
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1262,14 +1282,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode; 
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1282,14 +1304,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIt
 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myOld;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
diff --git a/tests/bugs/caf/bug26428 b/tests/bugs/caf/bug26428
new file mode 100644 (file)
index 0000000..94cfb8c
--- /dev/null
@@ -0,0 +1,15 @@
+puts "============"
+puts "OCC26428"
+puts "============"
+puts ""
+###################################################################################
+# TNaming_Selector::Solve crash for empty named shape.
+###################################################################################
+
+NewDocument D BinOcaf
+
+box b 10 20 30
+
+CheckNSIter D 0:1 b 1
+
+CheckNSIter D 0:1 b 0