From 02d972412855251acc3a7a60a7ed96078ff3401b Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 3 Jan 2025 19:10:25 -0800 Subject: [PATCH] SmallMatrix: Assert Lower Bound Index 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. --- Src/Base/AMReX_SmallMatrix.H | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Src/Base/AMReX_SmallMatrix.H b/Src/Base/AMReX_SmallMatrix.H index 05305d1839..b1b6ee3040 100644 --- a/Src/Base/AMReX_SmallMatrix.H +++ b/Src/Base/AMReX_SmallMatrix.H @@ -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]; @@ -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]; @@ -132,6 +134,7 @@ namespace amrex { if constexpr (StartIndex == 1) { --i; } + AMREX_ASSERT(i >= 0); AMREX_ASSERT(i < NRows*NCols); return m_mat[i]; } @@ -144,6 +147,7 @@ namespace amrex { if constexpr (StartIndex == 1) { --i; } + AMREX_ASSERT(i >= 0); AMREX_ASSERT(i < NRows*NCols); return m_mat[i]; } @@ -156,6 +160,7 @@ namespace amrex { if constexpr (StartIndex == 1) { --i; } + AMREX_ASSERT(i >= 0); AMREX_ASSERT(i < NRows*NCols); return m_mat[i]; } @@ -168,6 +173,7 @@ namespace amrex { if constexpr (StartIndex == 1) { --i; } + AMREX_ASSERT(i >= 0); AMREX_ASSERT(i < NRows*NCols); return m_mat[i]; }