]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed crash in HitTest() with y position below the last line
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Aug 2001 15:37:17 +0000 (15:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Aug 2001 15:37:17 +0000 (15:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11471 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/listctrl.cpp

index 3ca9aa51ac246068d14ce0ea51f89c1c82a66568..59f91bb29b3399b0c9a8067e85e2244063c5caa6 100644 (file)
@@ -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);