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 c22f0be
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 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

0 comments on commit c22f0be

Please sign in to comment.