Skip to content

Commit

Permalink
Fix New Coverity Scan Warning
Browse files Browse the repository at this point in the history
Coverity Scan warned about logically dead code, because index >= 0 && index
< NReal can never be true if NReal is 0.
  • Loading branch information
WeiqunZhang committed Aug 1, 2023
1 parent ebe604a commit de82830
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions Src/Particle/AMReX_StructOfArrays.H
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ struct StructOfArrays {
*/
[[nodiscard]] RealVector& GetRealData (const int index) {
AMREX_ASSERT(index >= 0 && index < NReal + static_cast<int>(m_runtime_rdata.size()));
if (index >= 0 && index < NReal) return m_rdata[index];
else {
if constexpr (NReal == 0) {
AMREX_ASSERT(m_defined);
return m_runtime_rdata[index - NReal];
return m_runtime_rdata[index];
} else {
if (index < NReal) {
return m_rdata[index];
} else {
AMREX_ASSERT(m_defined);
return m_runtime_rdata[index - NReal];
}
}
}

Expand All @@ -55,10 +61,16 @@ struct StructOfArrays {
*/
[[nodiscard]] const RealVector& GetRealData (const int index) const {
AMREX_ASSERT(index >= 0 && index < NReal + static_cast<int>(m_runtime_rdata.size()));
if (index >= 0 && index < NReal) return m_rdata[index];
else {
if constexpr (NReal == 0) {
AMREX_ASSERT(m_defined);
return m_runtime_rdata[index - NReal];
return m_runtime_rdata[index];
} else {
if (index < NReal) {
return m_rdata[index];
} else {
AMREX_ASSERT(m_defined);
return m_runtime_rdata[index - NReal];
}
}
}

Expand All @@ -68,10 +80,16 @@ struct StructOfArrays {
*/
[[nodiscard]] IntVector& GetIntData (const int index) {
AMREX_ASSERT(index >= 0 && index < NInt + static_cast<int>(m_runtime_idata.size()));
if (index >= 0 && index < NInt) return m_idata[index];
else {
if constexpr (NInt == 0) {
AMREX_ASSERT(m_defined);
return m_runtime_idata[index - NInt];
return m_runtime_idata[index];
} else {
if (index < NInt) {
return m_idata[index];
} else {
AMREX_ASSERT(m_defined);
return m_runtime_idata[index - NInt];
}
}
}

Expand All @@ -82,10 +100,16 @@ struct StructOfArrays {
*/
[[nodiscard]] const IntVector& GetIntData (const int index) const {
AMREX_ASSERT(index >= 0 && index < NInt + static_cast<int>(m_runtime_idata.size()));
if (index >= 0 && index < NInt) return m_idata[index];
else {
if constexpr (NInt == 0) {
AMREX_ASSERT(m_defined);
return m_runtime_idata[index - NInt];
return m_runtime_idata[index];
} else {
if (index < NInt) {
return m_idata[index];
} else {
AMREX_ASSERT(m_defined);
return m_runtime_idata[index - NInt];
}
}
}

Expand Down Expand Up @@ -148,8 +172,12 @@ struct StructOfArrays {

void resize (size_t count)
{
for (int i = 0; i < NReal; ++i) m_rdata[i].resize(count);
for (int i = 0; i < NInt; ++i) m_idata[i].resize(count);
if constexpr (NReal > 0) {
for (int i = 0; i < NReal; ++i) { m_rdata[i].resize(count); }
}
if constexpr (NInt > 0) {
for (int i = 0; i < NInt; ++i) { m_idata[i].resize(count); }
}
for (int i = 0; i < int(m_runtime_rdata.size()); ++i) m_runtime_rdata[i].resize(count);
for (int i = 0; i < int(m_runtime_idata.size()); ++i) m_runtime_idata[i].resize(count);
}
Expand Down

0 comments on commit de82830

Please sign in to comment.