mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +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:
@@ -151,13 +151,14 @@ class NCollection_DataMap : public NCollection_BaseMap
|
||||
this->exchangeMapsData (theOther);
|
||||
}
|
||||
|
||||
//! Assignment
|
||||
//! Assignment.
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_DataMap& Assign (const NCollection_DataMap& theOther)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
ReSize (theOther.Extent()-1);
|
||||
Iterator anIter(theOther);
|
||||
for (; anIter.More(); anIter.Next())
|
||||
|
@@ -140,13 +140,14 @@ class NCollection_DoubleMap : public NCollection_BaseMap
|
||||
this->exchangeMapsData (theOther);
|
||||
}
|
||||
|
||||
//! Assignment
|
||||
//! Assignment.
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_DoubleMap& Assign (const NCollection_DoubleMap& theOther)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
ReSize (theOther.Extent()-1);
|
||||
Iterator anIter(theOther);
|
||||
for (; anIter.More(); anIter.Next())
|
||||
@@ -167,7 +168,7 @@ class NCollection_DoubleMap : public NCollection_BaseMap
|
||||
|
||||
//! Assignment operator
|
||||
NCollection_DoubleMap& operator= (const NCollection_DoubleMap& theOther)
|
||||
{
|
||||
{
|
||||
return Assign (theOther);
|
||||
}
|
||||
|
||||
|
@@ -180,13 +180,14 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap
|
||||
this->exchangeMapsData (theOther);
|
||||
}
|
||||
|
||||
//! Assignment
|
||||
//! Assignment.
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_IndexedDataMap& Assign (const NCollection_IndexedDataMap& theOther)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
ReSize (theOther.Extent()-1);
|
||||
Standard_Integer i;
|
||||
for (i=1; i<=theOther.Extent(); i++)
|
||||
@@ -207,7 +208,7 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap
|
||||
|
||||
//! Assignment operator
|
||||
NCollection_IndexedDataMap& operator= (const NCollection_IndexedDataMap& theOther)
|
||||
{
|
||||
{
|
||||
return Assign (theOther);
|
||||
}
|
||||
|
||||
|
@@ -150,13 +150,14 @@ class NCollection_IndexedMap : public NCollection_BaseMap
|
||||
this->exchangeMapsData (theOther);
|
||||
}
|
||||
|
||||
//! Assign
|
||||
//! Assign.
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_IndexedMap& Assign (const NCollection_IndexedMap& theOther)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
ReSize (theOther.Extent()-1);
|
||||
Standard_Integer i, iLength=theOther.Extent();
|
||||
for (i=1; i<=iLength; i++)
|
||||
|
@@ -73,20 +73,21 @@ public:
|
||||
Standard_Integer Size (void) const
|
||||
{ return Extent(); }
|
||||
|
||||
//! Replace this list by the items of another list (theOther parameter)
|
||||
void Assign (const NCollection_List& theOther)
|
||||
//! Replace this list by the items of another list (theOther parameter).
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_List& Assign (const NCollection_List& theOther)
|
||||
{
|
||||
if (this != &theOther) {
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
appendList(theOther.PFirst());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Replacement operator
|
||||
NCollection_List& operator= (const NCollection_List& theOther)
|
||||
{
|
||||
Assign (theOther);
|
||||
return *this;
|
||||
return Assign (theOther);
|
||||
}
|
||||
|
||||
//! Clear this list
|
||||
|
@@ -139,13 +139,14 @@ class NCollection_Map : public NCollection_BaseMap
|
||||
this->exchangeMapsData (theOther);
|
||||
}
|
||||
|
||||
//! Assign
|
||||
//! Assign.
|
||||
//! This method does not change the internal allocator.
|
||||
NCollection_Map& Assign (const NCollection_Map& theOther)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
|
||||
Clear(theOther.myAllocator);
|
||||
Clear();
|
||||
ReSize (theOther.Extent()-1);
|
||||
Iterator anIter(theOther);
|
||||
for (; anIter.More(); anIter.Next())
|
||||
@@ -155,7 +156,7 @@ class NCollection_Map : public NCollection_BaseMap
|
||||
|
||||
//! Assign operator
|
||||
NCollection_Map& operator= (const NCollection_Map& theOther)
|
||||
{
|
||||
{
|
||||
return Assign(theOther);
|
||||
}
|
||||
|
||||
|
@@ -170,12 +170,13 @@ public:
|
||||
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)
|
||||
{
|
||||
if (this == &theOther)
|
||||
return *this;
|
||||
Clear (theOther.myAllocator);
|
||||
Clear ();
|
||||
Node * pCur = (Node *) theOther.myFirstItem;
|
||||
while (pCur) {
|
||||
Node* pNew = new (this->myAllocator) Node (pCur->Value());
|
||||
|
Reference in New Issue
Block a user