Skip to content

Commit

Permalink
#210 Safety range for GraphicsBlockItem intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
yse committed Nov 13, 2023
1 parent af758e2 commit 04a4721
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion profiler_gui/graphics_block_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit 04a4721

Please sign in to comment.