]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't assert if starting search position in LVN_ODFINDITEM is invalid.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 9 Mar 2011 09:28:34 +0000 (09:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 9 Mar 2011 09:28:34 +0000 (09:28 +0000)
Just use wxLogDebug() if this happens, asserting here is not the right thing
to do as it doesn't indicate an error in the program but rather invalid
external input and, moreover, we can recover from it easily.

No changes in behaviour in normal case.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/listctrl.cpp

index 13525bf4b8dca432a55cdfbda8729ed74b67ce1a..aa9ccb521b87e0fa9a4e26f5112bae1e6708d33f 100644 (file)
@@ -2391,10 +2391,25 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 
                     // this is the first item we should examine, search from it
                     // wrapping if necessary
-                    const int startPos = pFindInfo->iStart;
+                    int startPos = pFindInfo->iStart;
                     const int maxPos = GetItemCount();
-                    wxCHECK_MSG( startPos <= maxPos, false,
-                                 wxT("bad starting position in LVN_ODFINDITEM") );
+
+                    // Check that the index is valid to ensure that our loop
+                    // below always terminates.
+                    if ( startPos < 0 || startPos >= maxPos )
+                    {
+                        // When the last item in the control is selected,
+                        // iStart is really set to (invalid) maxPos index so
+                        // accept this silently.
+                        if ( startPos != maxPos )
+                        {
+                            wxLogDebug(wxT("Ignoring invalid search start ")
+                                       wxT("position %d in list control with ")
+                                       wxT("%d items."), startPos, maxPos);
+                        }
+
+                        startPos = 0;
+                    }
 
                     int currentPos = startPos;
                     do