From 2b01bc7a94237334fbc5d07bfe59dce47ef8e7a8 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 8 Mar 2026 20:45:30 +0100 Subject: [PATCH] Guard against past-end iterator in etl::rotate() And fix scope of rotate_right_by_one for etl::rotate() --- include/etl/algorithm.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index d6b144d5..c52d445c 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -1366,6 +1366,15 @@ namespace etl ETL_CONSTEXPR14 TIterator rotate(TIterator first, TIterator middle, TIterator last) { + if (first == middle) + { + return last; + } + if (middle == last) + { + return first; + } + if (etl::next(first) == middle) { return private_algorithm::rotate_left_by_one(first, last); @@ -1374,7 +1383,7 @@ namespace etl #if ETL_USING_CPP20 if (etl::next(middle) == last) { - if ETL_IF_CONSTEXPR(!etl::is_forward_iterator::value) + if ETL_IF_CONSTEXPR(etl::is_bidirectional_iterator_concept::value) { return private_algorithm::rotate_right_by_one(first, last); }