From 9fc3681aebfa88ca2a6392422d99558654c6dcdb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 7 Apr 2007 23:36:08 +0000 Subject: [PATCH] don't crash when IsEmpty() is called on invalid bundle; don't assert if GetIcon(-1) is called on an invalid or empty bundle as existing code expects to be able to do it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45320 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/iconbndl.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/common/iconbndl.cpp b/src/common/iconbndl.cpp index 19ede4871a..cedfb1bdee 100644 --- a/src/common/iconbndl.cpp +++ b/src/common/iconbndl.cpp @@ -149,11 +149,7 @@ void wxIconBundle::AddIcon(const wxString& file, long type) wxIcon wxIconBundle::GetIcon(const wxSize& size) const { - wxCHECK_MSG( IsOk(), wxNullIcon, _T("invalid icon bundle") ); - - const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons; - - const size_t count = iconArray.size(); + const size_t count = GetIconCount(); // optimize for the common case of icon bundles containing one icon only wxIcon iconBest; @@ -164,7 +160,7 @@ wxIcon wxIconBundle::GetIcon(const wxSize& size) const break; case 1: - iconBest = iconArray[0]; + iconBest = M_ICONBUNDLEDATA->m_icons[0]; break; default: @@ -172,6 +168,7 @@ wxIcon wxIconBundle::GetIcon(const wxSize& size) const wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ), sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y ); + const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons; for ( size_t i = 0; i < count; i++ ) { const wxIcon& icon = iconArray[i]; @@ -227,11 +224,13 @@ void wxIconBundle::AddIcon(const wxIcon& icon) size_t wxIconBundle::GetIconCount() const { - return M_ICONBUNDLEDATA->m_icons.size(); + return IsOk() ? M_ICONBUNDLEDATA->m_icons.size() : 0; } wxIcon wxIconBundle::GetIconByIndex(size_t n) const { + wxCHECK_MSG( n < GetIconCount(), wxNullIcon, _T("invalid index") ); + return M_ICONBUNDLEDATA->m_icons[n]; } -- 2.47.2