From: Vadim Zeitlin Date: Sat, 25 Aug 2001 15:37:17 +0000 (+0000) Subject: fixed crash in HitTest() with y position below the last line X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fc4f1d5f6bc52ff1ec80cbd52acb2c6f657ec79c fixed crash in HitTest() with y position below the last line git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11471 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 3ca9aa51ac..59f91bb29b 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2361,6 +2361,8 @@ wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const long wxListMainWindow::HitTestLine(size_t line, int x, int y) const { + wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); + wxListLineData *ld = GetLine(line); if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) @@ -4105,18 +4107,22 @@ long wxListMainWindow::HitTest( int x, int y, int &flags ) { CalcUnscrolledPosition( x, y, &x, &y ); + size_t count = GetItemCount(); + if ( HasFlag(wxLC_REPORT) ) { size_t current = y / GetLineHeight(); - flags = HitTestLine(current, x, y); - if ( flags ) - return current; + if ( current < count ) + { + flags = HitTestLine(current, x, y); + if ( flags ) + return current; + } } else // !report { // TODO: optimize it too! this is less simple than for report view but // enumerating all items is still not a way to do it!! - size_t count = GetItemCount(); for ( size_t current = 0; current < count; current++ ) { flags = HitTestLine(current, x, y);