From 4259c6b89acac9f50cc728cd7a5b1af1b9690f36 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 30 Sep 2021 09:31:48 +0200 Subject: [PATCH] add some null pointer checks does no harm and aids static analyzers --- src/ASM/DomainDecomposition.C | 6 ++++++ src/LinAlg/PETScMatrix.C | 3 +++ src/LinAlg/SAM.C | 2 +- src/Utility/Functions.C | 9 +++++++-- src/Utility/HDF5Writer.C | 3 +++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ASM/DomainDecomposition.C b/src/ASM/DomainDecomposition.C index a0345608..556f5aab 100644 --- a/src/ASM/DomainDecomposition.C +++ b/src/ASM/DomainDecomposition.C @@ -126,6 +126,9 @@ OrientIterator::OrientIterator(const ASMbase* pch, DomainDecomposition:: OrientIterator::OrientIterator(const ASMbase* pch, int orient, int lIdx) { + if (!pch) + return; + const ASMstruct* spch = dynamic_cast(pch); if (!spch) { nodes.resize(pch->getNoBoundaryElms(lIdx, pch->getNoSpaceDim()-1)); @@ -453,6 +456,9 @@ void DomainDecomposition::setupNodeNumbers(int basis, IntVec& lNodes, const ASMbase* pch, int dim, int lidx, int thick, int orient) { + if (!pch) + return; + if (basis != 0) // specified base cbasis = utl::getDigits(basis); else if (dim == 0 || (dim == 1 && pch->getNoSpaceDim() == 3)) diff --git a/src/LinAlg/PETScMatrix.C b/src/LinAlg/PETScMatrix.C index 62eacff8..0665dc95 100644 --- a/src/LinAlg/PETScMatrix.C +++ b/src/LinAlg/PETScMatrix.C @@ -587,6 +587,9 @@ bool PETScMatrix::solveDirect(PETScVector& B) // Set correct number of rows and columns for matrix. size_t nrow = IA.size()-1; + if (nrow == 0 || IA.empty()) + return false; + MatSetSizes(pA, nrow, nrow, PETSC_DECIDE, PETSC_DECIDE); MatSetFromOptions(pA); PetscInt max = 0; diff --git a/src/LinAlg/SAM.C b/src/LinAlg/SAM.C index 59c8d92a..4dfeb13a 100644 --- a/src/LinAlg/SAM.C +++ b/src/LinAlg/SAM.C @@ -208,7 +208,7 @@ bool SAM::initSystemEquations () std::cout <<"SAM::initSystemEquations()"<< std::endl; #endif if (!msc && ndof > 0) return false; - if (!mpmceq && nceq > 0) return false; + if ((!msc || !mpmceq) && nceq > 0) return false; // Initialize the DOF-to-equation connectivity array int i, j, ierr = 0; diff --git a/src/Utility/Functions.C b/src/Utility/Functions.C index 8d7e6ab2..9f491a40 100644 --- a/src/Utility/Functions.C +++ b/src/Utility/Functions.C @@ -730,7 +730,7 @@ static const ScalarFunc* parseFunction (const char* type, char* cline, Real C) if (cline) IFEM::cout <<"*"<< scale; return new LinearFunc(fname,colum,scale); } - else if (strncasecmp(type,"Constant",8) == 0) + else if (strncasecmp(type,"Constant",8) == 0 && cline) { Real value = atof(cline); IFEM::cout << value; @@ -738,7 +738,12 @@ static const ScalarFunc* parseFunction (const char* type, char* cline, Real C) } else // linear in time { - Real scale = atof(strncasecmp(type,"Lin",3) == 0 ? cline : type); + Real scale; + if (type && cline) + scale = atof(strncasecmp(type,"Lin",3) == 0 ? cline : type); + else + scale = 1.0; + IFEM::cout << scale <<"*t"; return new LinearFunc(C*scale); } diff --git a/src/Utility/HDF5Writer.C b/src/Utility/HDF5Writer.C index 6fda9f90..7b3f65ac 100644 --- a/src/Utility/HDF5Writer.C +++ b/src/Utility/HDF5Writer.C @@ -353,6 +353,9 @@ void HDF5Writer::writeSIM (int level, const DataEntry& entry, { Vector psol; ASMbase* pch = sim->getPatch(loc); + if (!pch) + continue; + if (results & DataExporter::PRIMARY && !sol->empty()) { size_t ndof1 = sim->extractPatchSolution(*sol,psol,pch,entry.second.ncmps, usedescription ? 1 : 0);