From f60da6ec4947909c8299a71c6a7f2ad7f793686c Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 24 Oct 2018 16:51:48 +0100 Subject: [PATCH] Bugfix: operator= for PtrList needs to check if source pointers are set --- src/foam/containers/Lists/PtrList/PtrList.C | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/foam/containers/Lists/PtrList/PtrList.C b/src/foam/containers/Lists/PtrList/PtrList.C index e4634bd97..28658180f 100644 --- a/src/foam/containers/Lists/PtrList/PtrList.C +++ b/src/foam/containers/Lists/PtrList/PtrList.C @@ -263,26 +263,35 @@ Foam::PtrList& Foam::PtrList::operator=(const PtrList& a) << abort(FatalError); } - if (size() == 0) + if (this->size() == 0) { - setSize(a.size()); + this->setSize(a.size()); 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) { - (*this)[i] = a[i]; + if (a.set(i)) + { + (*this)[i] = a[i]; + } } } else { FatalErrorIn("PtrList::operator=(const PtrList&)") << "bad size: " << a.size() + << " for type " << typeid(T).name() << abort(FatalError); }