BUG: invalid pointer reference for optional coordinate system lookup

- code remnant from separate lookup + construct of coordinateSystem
  (7b2bcfda0b).
  Apply consistent use of coordinateSystem::NewIfPresent to avoid
  these types of coding mishaps
This commit is contained in:
Mark Olesen
2022-10-06 12:49:23 +02:00
parent 793433da72
commit bcd461926c
4 changed files with 24 additions and 54 deletions

View File

@ -147,14 +147,12 @@ bool Foam::blockMesh::readPointTransforms(const dictionary& dict)
{
transformType_ = transformTypes::NO_TRANSFORM;
const dictionary* dictptr = dict.findDict("transform", keyType::LITERAL);
// Optional (cartesian) coordinate system transform
auto csysPtr = coordinateSystem::NewIfPresent(dict, "transform");
if (dictptr)
if (csysPtr)
{
// Optional cartesian coordinate system transform, since JUL-2021
// - 'origin' (READ_IF_PRESENT)
transform_ =
coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
transform_ = csysPtr();
// Non-zero origin?
if (magSqr(transform_.origin()) > ROOTVSMALL)

View File

@ -84,14 +84,12 @@ void Foam::geomDecomp::readCoeffs()
}
setOrder();
// Optional cartesian coordinate system transform
const dictionary* dictptr =
coeffsDict_.findDict("transform", keyType::LITERAL);
// Optional (cartesian) coordinate system transform
auto csysPtr = coordinateSystem::NewIfPresent(coeffsDict_, "transform");
if (dictptr)
if (csysPtr)
{
// 'origin' (READ_IF_PRESENT)
csys_ = coordinateSystem(*dictptr, IOobjectOption::READ_IF_PRESENT);
csys_ = csysPtr();
}
else if (equal(delta_, 0))
{

View File

@ -60,34 +60,21 @@ Foam::plane Foam::sampledCuttingPlane::definePlane
{
plane pln(dict);
bool adjust = false;
const dictionary* dictptr = nullptr;
coordSystem::cartesian cs;
// Optional (cartesian) coordinate transform.
// - with registry to allow lookup from globally defined systems
// Create with registry to allow lookup from globally defined
// coordinate systems.
auto csysPtr = coordinateSystem::NewIfPresent(mesh, dict);
auto csPtr = coordinateSystem::NewIfPresent(mesh, *dictptr);
if (csPtr)
if (!csysPtr)
{
adjust = true;
cs = csPtr();
csysPtr = coordinateSystem::NewIfPresent(dict, "transform");
}
else if
(
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
)
{
// 'origin' (READ_IF_PRESENT)
adjust = true;
cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
}
// Make plane relative to the Cartesian coordinate system
if (adjust)
if (csysPtr)
{
coordSystem::cartesian cs(csysPtr());
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());

View File

@ -58,34 +58,21 @@ Foam::plane Foam::sampledPlane::definePlane
{
plane pln(dict);
bool adjust = false;
const dictionary* dictptr = nullptr;
coordSystem::cartesian cs;
// Optional (cartesian) coordinate transform.
// - with registry to allow lookup from globally defined systems
// Create with registry to allow lookup from globally defined
// coordinate systems.
auto csysPtr = coordinateSystem::NewIfPresent(mesh, dict);
auto csPtr = coordinateSystem::NewIfPresent(mesh, dict);
if (csPtr)
if (!csysPtr)
{
adjust = true;
cs = csPtr();
csysPtr = coordinateSystem::NewIfPresent(dict, "transform");
}
else if
(
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
)
{
// 'origin' (READ_IF_PRESENT)
adjust = true;
cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
}
// Make plane relative to the Cartesian coordinate system
if (adjust)
if (csysPtr)
{
coordSystem::cartesian cs(csysPtr());
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());