add some null pointer checks

does no harm and aids static analyzers
This commit is contained in:
Arne Morten Kvarving
2021-09-30 09:31:48 +02:00
parent 875d413829
commit 4259c6b89a
5 changed files with 20 additions and 3 deletions

View File

@@ -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<const ASMstruct*>(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))

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);