Bugfix: operator= for PtrList needs to check if source pointers are set
This commit is contained in:
parent
2a04913eaf
commit
f60da6ec49
1 changed files with 14 additions and 5 deletions
|
@ -263,26 +263,35 @@ Foam::PtrList<T>& Foam::PtrList<T>::operator=(const PtrList<T>& a)
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size() == 0)
|
if (this->size() == 0)
|
||||||
{
|
{
|
||||||
setSize(a.size());
|
this->setSize(a.size());
|
||||||
|
|
||||||
forAll(*this, i)
|
forAll(*this, i)
|
||||||
{
|
{
|
||||||
ptrs_[i] = (a[i]).clone().ptr();
|
// Bugfix: only copy elements of a that have been set.
|
||||||
|
// HJ, 24/Oct/2018
|
||||||
|
if (a.set(i))
|
||||||
|
{
|
||||||
|
this->ptrs_[i] = (a[i]).clone().ptr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (a.size() == size())
|
else if (a.size() == this->size())
|
||||||
{
|
{
|
||||||
forAll(*this, i)
|
forAll(*this, i)
|
||||||
{
|
{
|
||||||
(*this)[i] = a[i];
|
if (a.set(i))
|
||||||
|
{
|
||||||
|
(*this)[i] = a[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorIn("PtrList::operator=(const PtrList<T>&)")
|
FatalErrorIn("PtrList::operator=(const PtrList<T>&)")
|
||||||
<< "bad size: " << a.size()
|
<< "bad size: " << a.size()
|
||||||
|
<< " for type " << typeid(T).name()
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue