]> OCCT Git - occt.git/commitdiff
0032044: Foundation Classes - NCollection_Array2::Resize() does not allocate pointer...
authorkgv <kgv@opencascade.com>
Sat, 9 Jan 2021 21:04:32 +0000 (00:04 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 12 Jan 2021 13:07:23 +0000 (16:07 +0300)
NCollection_Array2::Resize() has been fixed to set myDeletable before calling Allocate().

src/NCollection/NCollection_Array2.hxx
src/QANCollection/QANCollection_Test.cxx

index 1aa317b2c85d9b3470fc23dd73c06b43e58efe4e..4e6eb37c4088a775f4a49496a37b79b0cd5531f0 100644 (file)
@@ -349,10 +349,11 @@ public:
     }
     delete[] aTableOld;
 
+    const Standard_Boolean wasDeletable = myDeletable;
+    myDeletable = Standard_True;
     Allocate();
     if (!theToCopyData)
     {
-      myDeletable = Standard_True;
       return;
     }
 
@@ -366,11 +367,10 @@ public:
       }
     }
 
-    if (myDeletable)
+    if (wasDeletable)
     {
       delete[] aStartOld;
     }
-    myDeletable = Standard_True;
   }
 
   //! Destructor - releases the memory
index 3454695dac6300dcb06faa4deab54f5d0335de21..63432cc57b4701502b0762d391536ca77a503dac 100644 (file)
@@ -193,6 +193,8 @@ static void TestArray2  (QANCollection_Array2Func&     theA2)
   Handle(QANCollection_HArray2Func) aHa = new QANCollection_HArray2Func(aCArr);
   // Assign
   AssignCollection (aHa->ChangeArray2(), theA2);
+
+  delete[] rBlock;
 }
 
 // ===================== Test methods of List type ==========================
@@ -755,8 +757,17 @@ static Standard_Integer QANColTestArray2(Draw_Interpretor& di, Standard_Integer
     }
   }
 
-  QANCollection_Array2Func anArr2Copy2 = anArr2;
-  anArr2Copy2.Resize (LowerRow - 1, UpperRow - 1, LowerCol + 1, UpperCol + 1, false);
+  {
+    QANCollection_Array2Func anArr2Copy2 = anArr2;
+    anArr2Copy2.Resize (LowerRow - 1, UpperRow - 1, LowerCol + 1, UpperCol + 1, false);
+  }
+
+  {
+    // empty array resize
+    QANCollection_Array2Func anArr2Copy3;
+    anArr2Copy3.Resize (LowerRow, UpperRow, LowerCol, UpperCol, false);
+    anArr2Copy3 = anArr2;
+  }
 
   return 0;
 }