ENH: extend nullptr check for tmp ptr() method (#1775)

- Cannot call ptr_->clone() with a null pointer!
This commit is contained in:
Mark Olesen 2020-07-16 10:12:25 +02:00
parent fde93b6603
commit 6d4928d585
2 changed files with 15 additions and 14 deletions

View File

@ -259,8 +259,6 @@ inline T& Foam::tmp<T>::constCast() const
template<class T> template<class T>
inline T* Foam::tmp<T>::ptr() const inline T* Foam::tmp<T>::ptr() const
{
if (isTmp())
{ {
if (!ptr_) if (!ptr_)
{ {
@ -268,7 +266,10 @@ inline T* Foam::tmp<T>::ptr() const
<< typeName() << " deallocated" << typeName() << " deallocated"
<< abort(FatalError); << abort(FatalError);
} }
else if (!ptr_->unique())
if (isTmp())
{
if (!ptr_->unique())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Attempt to acquire pointer to object referred to" << "Attempt to acquire pointer to object referred to"

View File

@ -223,8 +223,6 @@ inline T& Foam::tmpNrc<T>::constCast() const
template<class T> template<class T>
inline T* Foam::tmpNrc<T>::ptr() const inline T* Foam::tmpNrc<T>::ptr() const
{
if (isTmp())
{ {
if (!ptr_) if (!ptr_)
{ {
@ -233,6 +231,8 @@ inline T* Foam::tmpNrc<T>::ptr() const
<< abort(FatalError); << abort(FatalError);
} }
if (isTmp())
{
T* p = ptr_; T* p = ptr_;
ptr_ = nullptr; ptr_ = nullptr;