WerWolv / libtesla

The support library for Tesla overlays
GNU General Public License v2.0
218 stars 49 forks source link

Fix crash when scrolling list due to iterator out of range #25

Closed diwo closed 4 years ago

diwo commented 4 years ago

Old implementation accesses out of range iterator which sometimes results in a crash.

For example this can happen in the following when m_entriesShown is larger than the size of m_items:

oldFocus == (this->m_items.begin() + this->m_offset + this->m_entriesShown - 2)->element

This fix changes all comparisons to be made against indexes instead. The number of "lead" spaces between top/bottom item and focused item has also been parameterized for clarity. The lead is reduced to 0 when m_entriesShown is 2 or less.