]> git.saurik.com Git - wxWidgets.git/commitdiff
Assert if an invalid column index is specified when inserting wxListCtrl item.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 3 Jun 2010 10:35:41 +0000 (10:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 3 Jun 2010 10:35:41 +0000 (10:35 +0000)
This also catches the case of inserting an item in a report mode wxListCtrl
without adding any columns to it first. Previously this did result in an
assert but with a less clear error message and, most importantly, still a
crash afterwards. Assert only now, don't crash.

The message could still be improved but hopefully people will be able to
understand that inserting items when no columns are defined is not the right
thing to do.

Closes #12119.

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

src/generic/listctrl.cpp

index a59e9dc976cf644e118ab8e0721e3362816fcd4d..b5b460022058c81c9728234ace4882fe4d1fa7d8 100644 (file)
@@ -4059,8 +4059,11 @@ void wxListMainWindow::InsertItem( wxListItem &item )
     {
         ResetVisibleLinesRange();
 
+        const unsigned col = item.GetColumn();
+        wxCHECK_RET( col < m_aColWidths.size(), "invalid item column" );
+
         // calculate the width of the item and adjust the max column width
-        wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn());
+        wxColWidthInfo *pWidthInfo = m_aColWidths.Item(col);
         int width = GetItemWidthWithImage(&item);
         item.SetWidth(width);
         if (width > pWidthInfo->nMaxWidth)