@@ -53,9 +53,14 @@ real_t tdl::getRecent( void ) const noexcept
5353/* ============================================================================*/
5454real_t tdl::getAtIndex ( const size_t i ) const noexcept
5555{
56+ size_t j = i;
57+
58+ if ( j >= itemCount ) {
59+ j = itemCount - 1U ;
60+ }
5661 /* cstat -MISRAC++2008-5-0-3*/
57- return ( ( wr >= rd ) && ( ( head + i ) >= wr ) ) ? rd[ itemCount - i ]
58- : *( rd - i );
62+ return ( ( wr >= rd ) && ( ( head + j ) >= wr ) ) ? rd[ itemCount - j ]
63+ : *( rd - j );
5964 /* cstat +MISRAC++2008-5-0-3*/
6065}
6166/* ============================================================================*/
@@ -65,23 +70,13 @@ void tdl::insertSample( const real_t sample ) noexcept
6570 insertNewest ( sample );
6671}
6772/* ============================================================================*/
68- const real_t & tdl::operator []( int index ) noexcept
73+ real_t tdl::operator []( int index ) noexcept
6974{
70- const size_t i = static_cast <size_t >( index );
71- /* cstat -MISRAC++2008-6-6-5*/
72- if ( ( index >= 0 ) && ( i < itemCount ) ) {
73- /* cstat -MISRAC++2008-5-0-3*/
74- return ( ( wr >= rd ) && ( ( head + i ) >= wr ) ) ? rd[ itemCount - i ]
75- : *( rd - i );
76- /* cstat +MISRAC++2008-5-0-3*/
77- }
78- else if ( -1 == index ) {
79- return ( ( rd + 1U ) >= tail ) ? head[ 0 ] : rd[ 1 ];
75+ if ( index < 0 ) {
76+ index = -index;
8077 }
81- else {
82- return undefined;
83- }
84- /* cstat +MISRAC++2008-6-6-5*/
78+
79+ return getAtIndex ( static_cast <size_t >( index ) );
8580}
8681/* ============================================================================*/
8782/* ! @endcond */
0 commit comments