From 762678a50f51274091d81e8afa72cc56621a0af1 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 5 Nov 2019 14:16:31 +1100 Subject: [PATCH] view: check the index is valid for the subscript operator --- view.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/view.hpp b/view.hpp index da349e9c..88717b3c 100644 --- a/view.hpp +++ b/view.hpp @@ -340,7 +340,7 @@ namespace cruft { [[nodiscard]] constexpr auto split (IndexT idx) const { - CHECK_LE (cruft::cast::lossless (idx), size ()); + CHECK_LIMIT (idx, IndexT {0u}, cruft::cast::lossless (size ())); auto last = m_begin; std::advance (last, idx); @@ -479,6 +479,7 @@ namespace cruft { constexpr auto&& operator[] (size_t idx) noexcept { + CHECK_LIMIT (idx, 0u, size ()); return *std::next (begin (), idx); } @@ -486,6 +487,7 @@ namespace cruft { constexpr auto&& operator[] (size_t idx) const noexcept { + CHECK_LIMIT (idx, 0u, size ()); return *std::next (begin (), idx); }