vcl/source/treelist/svimpbox.cxx | 12 +++++++----- vcl/source/treelist/treelist.cxx | 29 ++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-)
New commits: commit a1c835797d16383db1e67035c79b237c7706df0c Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Mon Dec 23 12:16:32 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Jan 1 20:31:31 2025 +0100 crashreporting: unify GetViewData and check it There are asserts all over the place but the crash is still reproducible, see https://crashreport.libreoffice.org/stats/signature/SvListView::SelectListEntry(SvTreeListEntry%20*,bool) So at least do not crash in a release build Change-Id: I1cde218cea449235f063198fdb03c5601dae3d0f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179239 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/vcl/source/treelist/svimpbox.cxx b/vcl/source/treelist/svimpbox.cxx index 985a7525c44c..640d0706548e 100644 --- a/vcl/source/treelist/svimpbox.cxx +++ b/vcl/source/treelist/svimpbox.cxx @@ -2833,14 +2833,16 @@ void SvImpLBox::PaintDDCursor(SvTreeListEntry* pEntry, bool bShow) if (pEntry) { - SvViewDataEntry* pViewData = m_pView->GetViewData(pEntry); - pViewData->SetDragTarget(bShow); + if (SvViewDataEntry* pViewData = m_pView->GetViewData(pEntry)) + { + pViewData->SetDragTarget(bShow); #ifdef MACOSX - // in MacOS we need to draw directly (as we are synchronous) or no invalidation happens - m_pView->PaintEntry1(*pEntry, GetEntryLine(pEntry), *m_pView->GetOutDev()); + // in MacOS we need to draw directly (as we are synchronous) or no invalidation happens + m_pView->PaintEntry1(*pEntry, GetEntryLine(pEntry), *m_pView->GetOutDev()); #else - InvalidateEntry(pEntry); + InvalidateEntry(pEntry); #endif + } } } diff --git a/vcl/source/treelist/treelist.cxx b/vcl/source/treelist/treelist.cxx index 94323be03bdb..4edb9332b488 100644 --- a/vcl/source/treelist/treelist.cxx +++ b/vcl/source/treelist/treelist.cxx @@ -578,6 +578,8 @@ sal_uInt32 SvTreeList::GetVisiblePos( const SvListView* pView, SvTreeListEntry c GetVisibleCount( const_cast<SvListView*>(pView) ); } const SvViewDataEntry* pViewData = pView->GetViewData( pEntry ); + if (!pViewData) + return 0; return pViewData->nVisPos; } @@ -593,8 +595,8 @@ sal_uInt32 SvTreeList::GetVisibleCount( SvListView* pView ) const SvTreeListEntry* pEntry = First(); // first entry is always visible while ( pEntry ) { - SvViewDataEntry* pViewData = pView->GetViewData( pEntry ); - pViewData->nVisPos = nPos; + if (SvViewDataEntry* pViewData = pView->GetViewData( pEntry )) + pViewData->nVisPos = nPos; nPos++; pEntry = NextVisible( pView, pEntry ); } @@ -851,12 +853,15 @@ void SvTreeList::SetAbsolutePositions() void SvListView::ExpandListEntry( SvTreeListEntry* pEntry ) { assert(pEntry && "Expand:View/Entry?"); - if ( IsExpanded(pEntry) ) + SvViewDataEntry* pViewData = GetViewData(pEntry); + if (!pViewData) + return; + + if (pViewData->IsExpanded()) return; DBG_ASSERT(!pEntry->m_Children.empty(), "SvTreeList::Expand: We expected to have child entries."); - SvViewDataEntry* pViewData = GetViewData(pEntry); pViewData->SetExpanded(true); SvTreeListEntry* pParent = pEntry->pParent; // if parent is visible, invalidate status data @@ -870,12 +875,15 @@ void SvListView::ExpandListEntry( SvTreeListEntry* pEntry ) void SvListView::CollapseListEntry( SvTreeListEntry* pEntry ) { assert(pEntry && "Collapse:View/Entry?"); - if ( !IsExpanded(pEntry) ) + SvViewDataEntry* pViewData = GetViewData( pEntry ); + if (!pViewData) + return; + + if (!pViewData->IsExpanded()) return; DBG_ASSERT(!pEntry->m_Children.empty(), "SvTreeList::Collapse: We expected to have child entries."); - SvViewDataEntry* pViewData = GetViewData( pEntry ); pViewData->SetExpanded(false); SvTreeListEntry* pParent = pEntry->pParent; @@ -889,7 +897,11 @@ void SvListView::CollapseListEntry( SvTreeListEntry* pEntry ) bool SvListView::SelectListEntry( SvTreeListEntry* pEntry, bool bSelect ) { DBG_ASSERT(pEntry,"Select:View/Entry?"); + SvViewDataEntry* pViewData = GetViewData( pEntry ); + if (!pViewData) + return false; + if ( bSelect ) { if ( pViewData->IsSelected() || !pViewData->IsSelectable() ) @@ -1338,6 +1350,7 @@ const SvViewDataEntry* SvListView::GetViewData( const SvTreeListEntry* pEntry ) { SvDataTable::const_iterator itr = m_pImpl->m_DataTable.find(const_cast<SvTreeListEntry*>(pEntry)); + assert(itr != m_pImpl->m_DataTable.end() && "Entry not in model or wrong view"); if (itr == m_pImpl->m_DataTable.end()) return nullptr; return itr->second.get(); @@ -1345,9 +1358,7 @@ const SvViewDataEntry* SvListView::GetViewData( const SvTreeListEntry* pEntry ) SvViewDataEntry* SvListView::GetViewData( SvTreeListEntry* pEntry ) { - SvDataTable::iterator itr = m_pImpl->m_DataTable.find( pEntry ); - assert(itr != m_pImpl->m_DataTable.end() && "Entry not in model or wrong view"); - return itr->second.get(); + return const_cast<SvViewDataEntry*>(const_cast<const SvListView*>(this)->GetViewData(pEntry)); } sal_Int32 SvTreeList::Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const