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

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

View File

@ -224,15 +224,15 @@ inline T& Foam::tmpNrc<T>::constCast() const
template<class T>
inline T* Foam::tmpNrc<T>::ptr() const
{
if (!ptr_)
{
FatalErrorInFunction
<< typeName() << " deallocated"
<< abort(FatalError);
}
if (isTmp())
{
if (!ptr_)
{
FatalErrorInFunction
<< typeName() << " deallocated"
<< abort(FatalError);
}
T* p = ptr_;
ptr_ = nullptr;