From 5275598bb737911f121060eb53b29987423e7578 Mon Sep 17 00:00:00 2001 From: Michael Bloom Date: Wed, 14 Feb 2024 15:35:24 -0500 Subject: [PATCH] In subspan function, add static checks on extents --- include/etl/span.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/etl/span.h b/include/etl/span.h index 797e35e5e..bcdb6a22f 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -331,6 +331,12 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR etl::span subspan() const ETL_NOEXCEPT { + //if extent is static, check that OFFSET is within the original span + static_assert((extent != etl::dynamic_extent) ? OFFSET <= extent : true); + + //if count is also static, check that OFFSET + COUNT is within the original span + static_assert((extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (extent - OFFSET) : true); + return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, (pbegin + Extent)) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); }