0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-25 23:40:51 +08:00

#210 Safety range for GraphicsBlockItem intersection

This commit is contained in:
Sergey Yagovtsev 2023-11-13 23:49:13 +03:00
parent af758e204d
commit 04a472121e

View File

@ -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;
});