diff options
author | 2023-01-02 15:05:07 +0100 | |
---|---|---|
committer | 2023-01-02 14:05:07 +0000 | |
commit | 1f25612f6d7efbb0ea9da179ed8ca5bc17784da8 (patch) | |
tree | 0efa7e763957be8d7df009a0980eab85ab1c8dcc /Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp | |
parent | 231a2372cf0fa593ec41dc30aab659e3cc235c92 (diff) | |
download | WarpX-1f25612f6d7efbb0ea9da179ed8ca5bc17784da8.tar.gz WarpX-1f25612f6d7efbb0ea9da179ed8ca5bc17784da8.tar.zst WarpX-1f25612f6d7efbb0ea9da179ed8ca5bc17784da8.zip |
fix two issues with unchecked possibly null pointer found with CodeQL (#3582)
Diffstat (limited to 'Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp')
-rw-r--r-- | Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp index ec01b4fc0..ad5722509 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp @@ -31,6 +31,7 @@ #include <iomanip> #include <istream> #include <memory> +#include <string> #include <utility> using namespace amrex; @@ -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(); } |