Skip to content

Commit

Permalink
SmallMatrix: Assert Lower Bound Index (#4283)
Browse files Browse the repository at this point in the history
## Summary

With 1-based indices, it is easy to access `0` and be out-of-bounds. Add
an assert for the lower bound of the index range as well.

## Additional background

Follow-up to #4188

## Checklist

The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
ax3l authored Jan 7, 2025
1 parent d7cc380 commit 3a34576
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Src/Base/AMReX_SmallMatrix.H
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace amrex {
--i;
--j;
}
AMREX_ASSERT(i >= 0 && j >= 0);
AMREX_ASSERT(i < NRows && j < NCols);
if constexpr (ORDER == Order::F) {
return m_mat[i+j*NRows];
Expand All @@ -116,6 +117,7 @@ namespace amrex {
--i;
--j;
}
AMREX_ASSERT(i >= 0 && j >= 0);
AMREX_ASSERT(i < NRows && j < NCols);
if constexpr (ORDER == Order::F) {
return m_mat[i+j*NRows];
Expand All @@ -132,6 +134,7 @@ namespace amrex {
if constexpr (StartIndex == 1) {
--i;
}
AMREX_ASSERT(i >= 0);
AMREX_ASSERT(i < NRows*NCols);
return m_mat[i];
}
Expand All @@ -144,6 +147,7 @@ namespace amrex {
if constexpr (StartIndex == 1) {
--i;
}
AMREX_ASSERT(i >= 0);
AMREX_ASSERT(i < NRows*NCols);
return m_mat[i];
}
Expand All @@ -156,6 +160,7 @@ namespace amrex {
if constexpr (StartIndex == 1) {
--i;
}
AMREX_ASSERT(i >= 0);
AMREX_ASSERT(i < NRows*NCols);
return m_mat[i];
}
Expand All @@ -168,6 +173,7 @@ namespace amrex {
if constexpr (StartIndex == 1) {
--i;
}
AMREX_ASSERT(i >= 0);
AMREX_ASSERT(i < NRows*NCols);
return m_mat[i];
}
Expand Down

0 comments on commit 3a34576

Please sign in to comment.