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; 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 transform_ = csysPtr();
// - 'origin' (READ_IF_PRESENT)
transform_ =
coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT);
// Non-zero origin? // Non-zero origin?
if (magSqr(transform_.origin()) > ROOTVSMALL) if (magSqr(transform_.origin()) > ROOTVSMALL)

View File

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

View File

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

View File

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