From 4945e596ee007e6d256a266957813772a1bdd7cc Mon Sep 17 00:00:00 2001 From: Chris Jones <jonesc@hep.phy.cam.ac.uk> Date: Mon, 16 Oct 2023 15:11:27 +0100 Subject: [PATCH] RichMirrorFinder: Add some asserts to validate indices are always in range. --- .../include/RichFutureUtils/RichMirrorFinder.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Rich/RichFutureUtils/include/RichFutureUtils/RichMirrorFinder.h b/Rich/RichFutureUtils/include/RichFutureUtils/RichMirrorFinder.h index 215b57534e9..3163d366d86 100644 --- a/Rich/RichFutureUtils/include/RichFutureUtils/RichMirrorFinder.h +++ b/Rich/RichFutureUtils/include/RichFutureUtils/RichMirrorFinder.h @@ -267,18 +267,25 @@ namespace Rich::Utils { /// Combine two (scalar) x,y indices in a single one [[nodiscard]] ScalarIndex xyIndex( const ScalarIndex ix, // const ScalarIndex iy ) const noexcept { + assert( ix < NXBINS ); + assert( iy < NYBINS ); return ( NYBINS * ix ) + iy; } /// Combine two (SIMD) x,y indices in a single one [[nodiscard]] typename SIMDIndices::IndexType xyIndex( const typename SIMDIndices::IndexType& ix, // const typename SIMDIndices::IndexType& iy // ) const noexcept { + assert( all_of( ix < SIMDIndices::IndexType( NXBINS ) ) ); + assert( all_of( iy < SIMDIndices::IndexType( NYBINS ) ) ); return ( SIMDIndices::IndexType( NYBINS ) * ix ) + iy; } public: /// Access the mirror for a given combined xy index (Scalar) - [[nodiscard]] MirrorNum get( const ScalarIndex ixy ) const noexcept { return ( *this )[ixy]; } + [[nodiscard]] MirrorNum get( const ScalarIndex ixy ) const noexcept { + assert( ixy < size() ); + return ( *this )[ixy]; + } /// Access the mirror for a given set of (x,y) indices (Scalar) [[nodiscard]] MirrorNum get( const ScalarIndex ix, // const ScalarIndex iy ) const noexcept { @@ -289,6 +296,7 @@ namespace Rich::Utils { /// Access the mirror for a given xy index (SIMD) [[nodiscard]] SIMDIndices get( const typename SIMDIndices::IndexType& ixy ) const noexcept { // gather SIMD lookup + assert( all_of( ixy < SIMDIndices::IndexType( size() ) ) ); return ( *this )[ixy]; } -- GitLab