X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/13771c0847632023793976a714242831fae1fd02..55c56a6d80f0ee4a4bf2add6ba1f62c02cbfc23e:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index ac31cb7f69..c6c67c9613 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2335,14 +2335,23 @@ long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state ) { - long ret = item; - wxCHECK_MSG( (ret == -1) || ((int)ret < GetItemCount()), -1, + long ret = item, + max = GetItemCount(); + wxCHECK_MSG( (ret == -1) || (ret < max), -1, _T("invalid listctrl index in GetNextItem()") ); // notice that we start with the next item (or the first one if item == -1) // and this is intentional to allow writing a simple loop to iterate over // all selected items - wxNode *node = m_lines.Nth( (size_t)++ret ); + ret++; + if ( ret == max ) + { + // this is not an error because the index was ok initially, just no + // such item + return -1; + } + + wxNode *node = m_lines.Nth( (size_t)ret ); while (node) { wxListLineData *line = (wxListLineData*)node->Data();