From 7ee99a529a4ebff46872a633fd1475cceea9fbb0 Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 3 Dec 2020 19:52:20 +0000 Subject: [PATCH] fix assertion messages for bounded_vector::back() method --- lib/include/srslte/adt/bounded_vector.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/include/srslte/adt/bounded_vector.h b/lib/include/srslte/adt/bounded_vector.h index 5cc3a124a..2b4e102c8 100644 --- a/lib/include/srslte/adt/bounded_vector.h +++ b/lib/include/srslte/adt/bounded_vector.h @@ -101,8 +101,16 @@ public: assert(i < size_ && "Array index is out of bounds."); return reinterpret_cast(buffer[i]); } - T& back() { return (*this)[size_ - 1]; } - const T& back() const { return (*this)[size_ - 1]; } + T& back() + { + assert(size_ > 0 && "Trying to get back of empty array."); + return *(begin() + size_ - 1); + } + const T& back() const + { + assert(size_ > 0 && "Trying to get back of empty array."); + return *(begin() + size_ - 1); + } T& front() { return (*this)[0]; } const T& front() const { return (*this)[0]; } T* data() { return reinterpret_cast(&buffer[0]); }