From 318e8eb3f2095205c8033e4c65fe6fedaf0822af Mon Sep 17 00:00:00 2001 From: Ryan <25047695+Ryanf55@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:37:09 -0700 Subject: [PATCH] Fix UB in SpiralIterator::operator++ (#481) * Calling pop_back on an iterator past the end is UB Signed-off-by: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> (cherry picked from commit 74dbbc83ad695c09bc60dcc856aa8a75741311a9) --- 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;