mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0025348: Method Assign of NCollection containers must not change own allocator of the target
Correct according to remarks of reviewer: - Assign() and operator=() should implement equal approach to allocators - Protect all collections against assignment to itself with operator=() Test-case for issue #25348
This commit is contained in:
parent
86766b0ee0
commit
5e452c37ee
@ -151,13 +151,14 @@ class NCollection_DataMap : public NCollection_BaseMap
|
|||||||
this->exchangeMapsData (theOther);
|
this->exchangeMapsData (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assignment
|
//! Assignment.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_DataMap& Assign (const NCollection_DataMap& theOther)
|
NCollection_DataMap& Assign (const NCollection_DataMap& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
ReSize (theOther.Extent()-1);
|
ReSize (theOther.Extent()-1);
|
||||||
Iterator anIter(theOther);
|
Iterator anIter(theOther);
|
||||||
for (; anIter.More(); anIter.Next())
|
for (; anIter.More(); anIter.Next())
|
||||||
|
@ -140,13 +140,14 @@ class NCollection_DoubleMap : public NCollection_BaseMap
|
|||||||
this->exchangeMapsData (theOther);
|
this->exchangeMapsData (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assignment
|
//! Assignment.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_DoubleMap& Assign (const NCollection_DoubleMap& theOther)
|
NCollection_DoubleMap& Assign (const NCollection_DoubleMap& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
ReSize (theOther.Extent()-1);
|
ReSize (theOther.Extent()-1);
|
||||||
Iterator anIter(theOther);
|
Iterator anIter(theOther);
|
||||||
for (; anIter.More(); anIter.Next())
|
for (; anIter.More(); anIter.Next())
|
||||||
@ -167,7 +168,7 @@ class NCollection_DoubleMap : public NCollection_BaseMap
|
|||||||
|
|
||||||
//! Assignment operator
|
//! Assignment operator
|
||||||
NCollection_DoubleMap& operator= (const NCollection_DoubleMap& theOther)
|
NCollection_DoubleMap& operator= (const NCollection_DoubleMap& theOther)
|
||||||
{
|
{
|
||||||
return Assign (theOther);
|
return Assign (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +180,14 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap
|
|||||||
this->exchangeMapsData (theOther);
|
this->exchangeMapsData (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assignment
|
//! Assignment.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_IndexedDataMap& Assign (const NCollection_IndexedDataMap& theOther)
|
NCollection_IndexedDataMap& Assign (const NCollection_IndexedDataMap& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
ReSize (theOther.Extent()-1);
|
ReSize (theOther.Extent()-1);
|
||||||
Standard_Integer i;
|
Standard_Integer i;
|
||||||
for (i=1; i<=theOther.Extent(); i++)
|
for (i=1; i<=theOther.Extent(); i++)
|
||||||
@ -207,7 +208,7 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap
|
|||||||
|
|
||||||
//! Assignment operator
|
//! Assignment operator
|
||||||
NCollection_IndexedDataMap& operator= (const NCollection_IndexedDataMap& theOther)
|
NCollection_IndexedDataMap& operator= (const NCollection_IndexedDataMap& theOther)
|
||||||
{
|
{
|
||||||
return Assign (theOther);
|
return Assign (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,13 +150,14 @@ class NCollection_IndexedMap : public NCollection_BaseMap
|
|||||||
this->exchangeMapsData (theOther);
|
this->exchangeMapsData (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assign
|
//! Assign.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_IndexedMap& Assign (const NCollection_IndexedMap& theOther)
|
NCollection_IndexedMap& Assign (const NCollection_IndexedMap& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
ReSize (theOther.Extent()-1);
|
ReSize (theOther.Extent()-1);
|
||||||
Standard_Integer i, iLength=theOther.Extent();
|
Standard_Integer i, iLength=theOther.Extent();
|
||||||
for (i=1; i<=iLength; i++)
|
for (i=1; i<=iLength; i++)
|
||||||
|
@ -73,20 +73,21 @@ public:
|
|||||||
Standard_Integer Size (void) const
|
Standard_Integer Size (void) const
|
||||||
{ return Extent(); }
|
{ return Extent(); }
|
||||||
|
|
||||||
//! Replace this list by the items of another list (theOther parameter)
|
//! Replace this list by the items of another list (theOther parameter).
|
||||||
void Assign (const NCollection_List& theOther)
|
//! This method does not change the internal allocator.
|
||||||
|
NCollection_List& Assign (const NCollection_List& theOther)
|
||||||
{
|
{
|
||||||
if (this != &theOther) {
|
if (this != &theOther) {
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
appendList(theOther.PFirst());
|
appendList(theOther.PFirst());
|
||||||
}
|
}
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Replacement operator
|
//! Replacement operator
|
||||||
NCollection_List& operator= (const NCollection_List& theOther)
|
NCollection_List& operator= (const NCollection_List& theOther)
|
||||||
{
|
{
|
||||||
Assign (theOther);
|
return Assign (theOther);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Clear this list
|
//! Clear this list
|
||||||
|
@ -139,13 +139,14 @@ class NCollection_Map : public NCollection_BaseMap
|
|||||||
this->exchangeMapsData (theOther);
|
this->exchangeMapsData (theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assign
|
//! Assign.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_Map& Assign (const NCollection_Map& theOther)
|
NCollection_Map& Assign (const NCollection_Map& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
Clear(theOther.myAllocator);
|
Clear();
|
||||||
ReSize (theOther.Extent()-1);
|
ReSize (theOther.Extent()-1);
|
||||||
Iterator anIter(theOther);
|
Iterator anIter(theOther);
|
||||||
for (; anIter.More(); anIter.Next())
|
for (; anIter.More(); anIter.Next())
|
||||||
@ -155,7 +156,7 @@ class NCollection_Map : public NCollection_BaseMap
|
|||||||
|
|
||||||
//! Assign operator
|
//! Assign operator
|
||||||
NCollection_Map& operator= (const NCollection_Map& theOther)
|
NCollection_Map& operator= (const NCollection_Map& theOther)
|
||||||
{
|
{
|
||||||
return Assign(theOther);
|
return Assign(theOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,12 +170,13 @@ public:
|
|||||||
this->myAllocator = theAllocator;
|
this->myAllocator = theAllocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Replace this sequence by the items of theOther
|
//! Replace this sequence by the items of theOther.
|
||||||
|
//! This method does not change the internal allocator.
|
||||||
NCollection_Sequence& Assign (const NCollection_Sequence& theOther)
|
NCollection_Sequence& Assign (const NCollection_Sequence& theOther)
|
||||||
{
|
{
|
||||||
if (this == &theOther)
|
if (this == &theOther)
|
||||||
return *this;
|
return *this;
|
||||||
Clear (theOther.myAllocator);
|
Clear ();
|
||||||
Node * pCur = (Node *) theOther.myFirstItem;
|
Node * pCur = (Node *) theOther.myFirstItem;
|
||||||
while (pCur) {
|
while (pCur) {
|
||||||
Node* pNew = new (this->myAllocator) Node (pCur->Value());
|
Node* pNew = new (this->myAllocator) Node (pCur->Value());
|
||||||
|
@ -2883,6 +2883,10 @@ static Standard_Integer OCC7570 (Draw_Interpretor& di, Standard_Integer n, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include <AIS_TypeFilter.hxx>
|
#include <AIS_TypeFilter.hxx>
|
||||||
|
//=======================================================================
|
||||||
|
//function : OCC25340
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/,
|
static Standard_Integer OCC25340 (Draw_Interpretor& /*theDI*/,
|
||||||
Standard_Integer /*theArgNb*/,
|
Standard_Integer /*theArgNb*/,
|
||||||
const char** /*theArgVec*/)
|
const char** /*theArgVec*/)
|
||||||
@ -2936,6 +2940,27 @@ static Standard_Integer OCC25100 (Draw_Interpretor& di, Standard_Integer argc, c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : OCC25348
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
static Standard_Integer OCC25348 (Draw_Interpretor& theDI,
|
||||||
|
Standard_Integer /*theArgNb*/,
|
||||||
|
const char** /*theArgVec*/)
|
||||||
|
{
|
||||||
|
Handle(NCollection_IncAllocator) anAlloc1;
|
||||||
|
NCollection_List<int> aList1(anAlloc1);
|
||||||
|
for (int i=0; i < 10; i++)
|
||||||
|
{
|
||||||
|
Handle(NCollection_IncAllocator) anAlloc2;
|
||||||
|
NCollection_List<int> aList2(anAlloc2);
|
||||||
|
aList2.Append(i);
|
||||||
|
aList1.Assign(aList2);
|
||||||
|
}
|
||||||
|
theDI << "Test complete\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
||||||
const char *group = "QABugs";
|
const char *group = "QABugs";
|
||||||
@ -2995,5 +3020,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
|||||||
theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group);
|
theCommands.Add ("OCC7570", "OCC7570 shape", __FILE__, OCC7570, group);
|
||||||
theCommands.Add ("OCC25100", "OCC25100 shape", __FILE__, OCC25100, group);
|
theCommands.Add ("OCC25100", "OCC25100 shape", __FILE__, OCC25100, group);
|
||||||
theCommands.Add ("OCC25340", "OCC25340", __FILE__, OCC25340, group);
|
theCommands.Add ("OCC25340", "OCC25340", __FILE__, OCC25340, group);
|
||||||
|
theCommands.Add ("OCC25348", "OCC25348", __FILE__, OCC25348, group);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
11
tests/bugs/fclasses/bug25348
Normal file
11
tests/bugs/fclasses/bug25348
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25348"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
#######################################################################################
|
||||||
|
# Method Assign of NCollection containers must not change own allocator of the target
|
||||||
|
#######################################################################################
|
||||||
|
|
||||||
|
pload QAcommands
|
||||||
|
|
||||||
|
OCC25348
|
Loading…
x
Reference in New Issue
Block a user