From 78b5ceb56ac6b698deed6f253527f5a0ca1dc6d4 Mon Sep 17 00:00:00 2001 From: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:38:19 -0700 Subject: [PATCH] Fix UB in SpiralIterator::operator++ * Calling pop_back on an iterator past the end is UB Signed-off-by: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> --- grid_map_core/src/iterators/SpiralIterator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grid_map_core/src/iterators/SpiralIterator.cpp b/grid_map_core/src/iterators/SpiralIterator.cpp index 6e094eb9a..168fb8564 100644 --- a/grid_map_core/src/iterators/SpiralIterator.cpp +++ b/grid_map_core/src/iterators/SpiralIterator.cpp @@ -66,6 +66,9 @@ const Eigen::Array2i & SpiralIterator::operator*() const SpiralIterator & SpiralIterator::operator++() { + if (isPastEnd()) { + return *this; + } pointsRing_.pop_back(); if (pointsRing_.empty() && !isPastEnd()) {generateRing();} return *this;