Skip to content

Commit

Permalink
Fix new coverity scan warnings (#4295)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jan 18, 2025
1 parent 59fb603 commit 1803a94
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions Src/Amr/AMReX_Amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,7 @@ Amr::printGridInfo (std::ostream& os,
int numgrid = static_cast<int>(bs.size());
Long ncells = amr_level[lev]->countCells();
double ntot = Geom(lev).Domain().d_numPts();
AMREX_ASSERT(ntot > 0.);
Real frac = Real(100.0 * double(ncells) / ntot);
const DistributionMapping& map = amr_level[lev]->get_new_data(0).DistributionMap();

Expand Down
6 changes: 3 additions & 3 deletions Src/Amr/AMReX_StateData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,13 @@ StateData::checkPoint (const std::string& name,
if (dump_old)
{
os << 2 << '\n' << mf_name_new << '\n' << mf_name_old << '\n';
fabArrayHeaderNames.push_back(mf_name_new);
fabArrayHeaderNames.push_back(mf_name_old);
fabArrayHeaderNames.push_back(std::move(mf_name_new));
fabArrayHeaderNames.push_back(std::move(mf_name_old));
}
else
{
os << 1 << '\n' << mf_name_new << '\n';
fabArrayHeaderNames.push_back(mf_name_new);
fabArrayHeaderNames.push_back(std::move(mf_name_new));
}
}
else
Expand Down
1 change: 1 addition & 0 deletions Src/AmrCore/AMReX_AmrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ AmrCore::printGridSummary (std::ostream& os, int min_lev, int max_lev) const noe
int numgrid = static_cast<int>(bs.size());
Long ncells = bs.numPts();
double ntot = Geom(lev).Domain().d_numPts();
AMREX_ASSERT(ntot > 0.);
Real frac = Real(100.0*double(ncells) / ntot);

os << " Level "
Expand Down
2 changes: 1 addition & 1 deletion Src/AmrCore/AMReX_Cluster.H
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public:
/**
* \brief Does cluster contain any points?
*/
[[nodiscard]] bool ok () const noexcept { return m_ar != nullptr && m_len > 0; }
[[nodiscard]] bool ok () const noexcept { return m_bx.d_numPts() > 0. && m_ar != nullptr && m_len > 0; }

/**
* \brief Returns number of tagged points in cluster.
Expand Down
2 changes: 2 additions & 0 deletions Src/Base/AMReX_DistributionMapping.H
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ void DistributionMapping::ComputeDistributionMappingEfficiency (
sum_weight += w;
}

AMREX_ASSERT(nprocs > 0 && max_weight > T(0));

*efficiency = static_cast<Real>(sum_weight) /
(static_cast<Real>(nprocs) * static_cast<Real>(max_weight));
}
Expand Down
2 changes: 2 additions & 0 deletions Src/Base/AMReX_DistributionMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ knapsack (const std::vector<Long>& wgts,
}
}

AMREX_ASSERT(nprocs > 0 && max_weight > Real(0));
efficiency = sum_weight/(static_cast<Real>(nprocs)*max_weight);

std::sort(wblv.begin(), wblv.end());
Expand Down Expand Up @@ -982,6 +983,7 @@ DistributionMapping::KnapSackProcessorMap (const DistributionMapping& olddm,
}
}

AMREX_ASSERT(max_weight > Real(0));
new_efficiency = avg_weight / max_weight;

if (new_efficiency < max_efficiency && wblv.size() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace amrex

// and record the siblings group
// (assumes: ascending and unique sets per cpuIndex)
uniqueThreadSets.insert(siblings);
uniqueThreadSets.insert(std::move(siblings));
cpuIndex++;
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ bldTable (const char*& str, ParmParse::Table& tab)
{
if ( cur_name.empty() )
{
cur_name = tokname;
cur_name = std::move(tokname);
break;
}
//
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_TinyProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ TinyProfiler::PrintStats (std::map<std::string,Stats>& regstats, double dt_max,
std::sort(allprocstats.begin(), allprocstats.end(), ProcStats::compin);
if (print_other_procstat) {
// make sure "Other" is printed at the end of the list
allprocstats.push_back(other_procstat);
allprocstats.push_back(std::move(other_procstat));
}
*os << "\n" << hline << "\n";
*os << std::left
Expand Down Expand Up @@ -805,7 +805,7 @@ TinyProfiler::PrintMemStats (std::map<std::string, MemStat>& memstats,
pst.avgmem_avg /= nprocs;
pst.maxmem_avg /= nprocs;
pst.fname = it.first;
allprocstats.push_back(pst);
allprocstats.push_back(std::move(pst));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_VisMF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ VisMF::Read (FabArray<FArrayBox> &mf,
frcIter = FileReadChains.find(fileName);
BL_ASSERT(frcIter != FileReadChains.end());
Vector<FabReadLink> &frc = frcIter->second;
for(NFilesIter nfi(std::move(fullFileName), readRanks); nfi.ReadyToRead(); ++nfi) {
for(NFilesIter nfi(std::move(fullFileName), std::move(readRanks)); nfi.ReadyToRead(); ++nfi) {

// ---- confirm the data is contiguous in the stream
Long firstOffset(-1);
Expand Down
12 changes: 5 additions & 7 deletions Src/LinearSolvers/MLMG/AMReX_MLCellLinOp.H
Original file line number Diff line number Diff line change
Expand Up @@ -1967,13 +1967,11 @@ MLCellLinOpT<MF>::computeVolInv () const
else
#endif
{
if (this->m_coarse_fine_bc_type == LinOpBCType::Dirichlet) {
m_volinv[amrlev][mglev]
= RT(1.0 / this->compactify(this->Geom(amrlev,mglev).Domain()).d_numPts());
} else {
m_volinv[amrlev][mglev]
= RT(1.0 / this->m_grids[amrlev][mglev].d_numPts());
}
auto const npts = (this->m_coarse_fine_bc_type == LinOpBCType::Dirichlet)
? this->compactify(this->Geom(amrlev,mglev).Domain()).d_numPts()
: this->m_grids[amrlev][mglev].d_numPts();
AMREX_ASSERT(npts > 0.);
m_volinv[amrlev][mglev] = RT(1.0 / npts);
}
};

Expand Down

0 comments on commit 1803a94

Please sign in to comment.