From 7451b5c459fc53b98f292e7442d36273e00c26af Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Dec 2011 13:56:47 +0000 Subject: [PATCH] Guard against a possible crash in wxListCtrl::DeleteColumn(). We could crash when deleting a column after switching to report view from icon view. As deleting a column works just fine under MSW in this case, make it work in the generic version as well. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70076 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8ad024386e..ddb6197f07 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3847,6 +3847,21 @@ void wxListMainWindow::DeleteColumn( int col ) for ( size_t i = 0; i < m_lines.GetCount(); i++ ) { wxListLineData * const line = GetLine(i); + + // In the following atypical but possible scenario it can be + // legal to call DeleteColumn() but the items may not have any + // values for it: + // 1. In report view, insert a second column. + // 2. Still in report view, add an item with 2 values. + // 3. Switch to an icon (or list) view. + // 4. Add an item -- necessarily with 1 value only. + // 5. Switch back to report view. + // 6. Call DeleteColumn(). + // So we need to check for this as otherwise we would simply crash + // if this happens. + if ( line->m_items.GetCount() <= static_cast(col) ) + continue; + wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); delete n->GetData(); line->m_items.Erase(n); -- 2.45.2