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. Its argument is because of
assertion on index >= 0 there is no need to test it again.
  • Loading branch information
WeiqunZhang committed Jul 29, 2023
1 parent 98d22d2 commit 11bf8e4
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions Src/Particle/AMReX_StructOfArrays.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ struct StructOfArrays {
* @param index component with 0...NReal-1 compile-time and NReal... runtime arguments
*/
[[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 {
AMREX_ASSERT(m_defined);
if (index >= 0 && index < NReal) {
return m_rdata[index];
} else {
AMREX_ASSERT((index-NReal) < static_cast<int>(m_runtime_rdata.size())
&& m_defined);
return m_runtime_rdata[index - NReal];
}
}
Expand All @@ -54,10 +55,11 @@ struct StructOfArrays {
* @param index component with 0...NReal-1 compile-time and NReal... runtime arguments
*/
[[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 {
AMREX_ASSERT(m_defined);
if (index >= 0 && index < NReal) {
return m_rdata[index];
} else {
AMREX_ASSERT((index-NReal) < static_cast<int>(m_runtime_rdata.size())
&& m_defined);
return m_runtime_rdata[index - NReal];
}
}
Expand All @@ -67,10 +69,11 @@ struct StructOfArrays {
* @param index component with 0...NInt-1 compile-time and NInt... runtime arguments
*/
[[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 {
AMREX_ASSERT(m_defined);
if (index >= 0 && index < NInt) {
return m_idata[index];
} else {
AMREX_ASSERT((index-NInt) < static_cast<int>(m_runtime_idata.size())
&& m_defined);
return m_runtime_idata[index - NInt];
}
}
Expand All @@ -81,10 +84,11 @@ struct StructOfArrays {
* @return
*/
[[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 {
AMREX_ASSERT(m_defined);
if (index >= 0 && index < NInt) {
return m_idata[index];
} else {
AMREX_ASSERT((index-NInt) < static_cast<int>(m_runtime_idata.size())
&& m_defined);
return m_runtime_idata[index - NInt];
}
}
Expand Down Expand Up @@ -148,8 +152,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 11bf8e4

Please sign in to comment.