From fd5c94428af5662db65b72de086bafff48a7475d Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Wed, 3 Apr 2024 11:19:40 -0400 Subject: [PATCH] fix potential dereferencing of null identified by coverity --- Source/gravity/Gravity.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/gravity/Gravity.cpp b/Source/gravity/Gravity.cpp index 02c02c0ea0..72a2565935 100644 --- a/Source/gravity/Gravity.cpp +++ b/Source/gravity/Gravity.cpp @@ -2966,9 +2966,9 @@ Gravity::set_mass_offset (Real time, bool multi_level) const { for (int lev = 0; lev <= parent->finestLevel(); lev++) { auto* cs = dynamic_cast(&parent->getLevel(lev)); - if (cs != nullptr) { - mass_offset += cs->volWgtSum("density", time); - } else { + if (cs != nullptr) { + mass_offset += cs->volWgtSum("density", time); + } else { amrex::Abort("unable to access volWgtSum"); } } @@ -2976,7 +2976,11 @@ Gravity::set_mass_offset (Real time, bool multi_level) const else { auto* cs = dynamic_cast(&parent->getLevel(0)); - mass_offset = cs->volWgtSum("density", time, false, false); // do not mask off fine grids + if (cs != nullptr) { + mass_offset = cs->volWgtSum("density", time, false, false); // do not mask off fine grids + } else { + amrex::Abort("unable to access volWgtSum"); + } } mass_offset = mass_offset / geom.ProbSize();