Skip to content

Commit

Permalink
fix two issues with unchecked possibly null pointer found with CodeQL (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafedeli88 authored Jan 2, 2023
1 parent 231a237 commit 1f25612
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <iomanip>
#include <istream>
#include <memory>
#include <string>
#include <utility>

using namespace amrex;
Expand Down Expand Up @@ -76,19 +77,19 @@ void LoadBalanceCosts::ComputeDiags (int step)
// get a reference to WarpX instance
auto& warpx = WarpX::GetInstance();

const amrex::LayoutData<amrex::Real>* cost = warpx.getCosts(0);

// judge if the diags should be done
// costs is initialized only if we're doing load balance
if (!m_intervals.contains(step+1) ||
!warpx.get_load_balance_intervals().isActivated() ) { return; }
!warpx.get_load_balance_intervals().isActivated() ) { return; }

// get number of boxes over all levels
auto nLevels = warpx.finestLevel() + 1;
int nBoxes = 0;
for (int lev = 0; lev < nLevels; ++lev)
{
cost = warpx.getCosts(lev);
const auto cost = warpx.getCosts(lev);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
cost, "ERROR: costs are not initialized on level " + std::to_string(lev) + " !");
nBoxes += cost->size();
}

Expand Down

0 comments on commit 1f25612

Please sign in to comment.