From 4293caf00c8c0a3ff3547a64f7f52899e293712a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 7 Nov 2021 08:53:56 +0100 Subject: [PATCH] fix crash in wxDataViewItem GetNextItem() when there are no item. Fixes #9540 https://gitlab.com/kicad/code/kicad/issues/9540 --- common/wxdataviewctrl_helpers.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/wxdataviewctrl_helpers.cpp b/common/wxdataviewctrl_helpers.cpp index 5e1ed258cf..a9cd9ba8b6 100644 --- a/common/wxdataviewctrl_helpers.cpp +++ b/common/wxdataviewctrl_helpers.cpp @@ -42,20 +42,29 @@ wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& a wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem ) { wxDataViewItem nextItem; + wxDataViewItem invalid; if( !aItem.IsOk() ) { // No selection. Select the first. wxDataViewItemArray children; aView.GetModel()->GetChildren( aItem, children ); - return children[0]; + + if( children.size() ) + return children[0]; + + return invalid; } if( aView.IsExpanded( aItem ) ) { wxDataViewItemArray children; aView.GetModel()->GetChildren( aItem, children ); - nextItem = children[0]; + + if( children.size() ) + return children[0]; + + return invalid; } else {