From: Vadim Zeitlin Date: Wed, 9 Mar 2011 09:28:34 +0000 (+0000) Subject: Don't assert if starting search position in LVN_ODFINDITEM is invalid. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/aab1681669d895adc4dd110e902ea1a71387bb6f Don't assert if starting search position in LVN_ODFINDITEM is invalid. 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 --- diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 13525bf4b8..aa9ccb521b 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -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