From 04a472121e80fb8f98e5785b0d43cdc2d0eda7ea Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Mon, 13 Nov 2023 23:49:13 +0300 Subject: [PATCH] #210 Safety range for GraphicsBlockItem intersection --- profiler_gui/graphics_block_item.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/profiler_gui/graphics_block_item.cpp b/profiler_gui/graphics_block_item.cpp index f8d322c..06f1e1f 100644 --- a/profiler_gui/graphics_block_item.cpp +++ b/profiler_gui/graphics_block_item.cpp @@ -1271,9 +1271,26 @@ const ::profiler_gui::EasyBlock* GraphicsBlockItem::intersect(const QPointF& _po while (i <= levelIndex) { const auto& level = m_levels[i]; + size_t levelSize = level.size(); + + auto firstItemIterator = level.begin(); + auto lastItemIterator = level.begin(); + + // Ensure that firstItem and lastItem are within the permissible range + if (firstItem < levelSize) { + std::advance(firstItemIterator, firstItem); + } else { + firstItemIterator = level.end(); + } + + if (lastItem <= levelSize) { + std::advance(lastItemIterator, lastItem); + } else { + lastItemIterator = level.end(); + } // Search for first visible item - auto first = ::std::lower_bound(level.begin() + firstItem, level.begin() + lastItem, _pos.x(), [](const ::profiler_gui::EasyBlockItem& _item, qreal _value) + auto first = ::std::lower_bound(firstItemIterator, lastItemIterator, _pos.x(), [](const ::profiler_gui::EasyBlockItem& _item, qreal _value) { return _item.left() < _value; });