From b150a58a1176f3f8c15d3f7d5ac34dbbb3b7fa61 Mon Sep 17 00:00:00 2001 From: Olaf Schumann Date: Thu, 6 Jan 2022 14:29:23 +0100 Subject: [PATCH] Iterator invalidation in lower/upper_bound_index Error ocured in regression_tests/filter_mesh/test.py --- include/openmc/search.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/openmc/search.h b/include/openmc/search.h index 3a6f9789d..f22cc1858 100644 --- a/include/openmc/search.h +++ b/include/openmc/search.h @@ -16,16 +16,14 @@ typename std::iterator_traits::difference_type lower_bound_index( { if (*first == value) return 0; - It index = std::lower_bound(first, last, value) - 1; - return (index == last) ? -1 : index - first; + return std::lower_bound(first, last, value) - first - 1; } template typename std::iterator_traits::difference_type upper_bound_index( It first, It last, const T& value) { - It index = std::upper_bound(first, last, value) - 1; - return (index == last) ? -1 : index - first; + return std::upper_bound(first, last, value) - first - 1; } } // namespace openmc