From 67841ebf14b9cba7ecfa6800160dc5a8c08f745f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 8 Dec 2020 23:42:11 -0600 Subject: [PATCH] feat(array): add TSBaseArray::CheckArrayBounds --- storm/array/TSBaseArray.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/storm/array/TSBaseArray.hpp b/storm/array/TSBaseArray.hpp index abc759d..f877cf0 100644 --- a/storm/array/TSBaseArray.hpp +++ b/storm/array/TSBaseArray.hpp @@ -1,6 +1,7 @@ #ifndef STORM_ARRAY_TS_BASE_ARRAY_HPP #define STORM_ARRAY_TS_BASE_ARRAY_HPP +#include "storm/Error.hpp" #include #include @@ -15,15 +16,34 @@ class TSBaseArray { virtual int32_t MemLineNo() const; T& operator[](uint32_t index); + void CheckArrayBounds(uint32_t index) const; uint32_t Count() const; void Clear(); }; template T& TSBaseArray::operator[](uint32_t index) { + this->CheckArrayBounds(index); return this->m_data[index]; } +template +void TSBaseArray::CheckArrayBounds(uint32_t index) const { + if (index < this->Count()) { + return; + } + + SErrDisplayErrorFmt( + 0x85100080, + this->MemFileName(), + this->MemLineNo(), + 1, + 1, + "index (0x%08X), array size (0x%08X)", + index, + this->Count()); +} + template uint32_t TSBaseArray::Count() const { return this->m_count;