sw/source/uibase/app/docst.cxx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
New commits: commit d29be0ee2435d035b29a8993387f47777776d3c7 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Aug 13 13:07:10 2024 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Aug 20 16:13:53 2024 +0200 fix null deref on fetching postit outliner Change-Id: I950c2c2e68090ad002401d3ff038dcd3d18e7da2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171822 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins (cherry picked from commit 2c2097a826f907cc5c70600c6c71f1d0a9eaeded) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172081 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index 4df37c96d590..433d91df57ce 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -88,6 +88,17 @@ using namespace ::com::sun::star; +static OutlinerView* lcl_GetPostItOutlinerView(SwWrtShell& rShell) +{ + SwPostItMgr* pPostItMgr = rShell.GetPostItMgr(); + if (!pPostItMgr) + return nullptr; + sw::annotation::SwAnnotationWin* pWin = pPostItMgr->GetActiveSidebarWin(); + if (!pWin) + return nullptr; + return pWin->GetOutlinerView(); +} + void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) { SfxWhichIter aIter(rSet); @@ -133,8 +144,8 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) } else if (pShell->GetSelectionType() == SelectionType::PostIt) { - auto pStyle = pShell->GetPostItMgr()->GetActiveSidebarWin()->GetOutlinerView()->GetStyleSheet(); - if (pStyle) + OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pShell); + if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr) aName = pStyle->GetName(); } else @@ -164,7 +175,8 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh) OUString aProgName; if (pShell->GetSelectionType() == SelectionType::PostIt) { - if (auto pStyle = pShell->GetPostItMgr()->GetActiveSidebarWin()->GetOutlinerView()->GetStyleSheet()) + OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pShell); + if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr) { aName = pStyle->GetName(); aProgName = SwStyleNameMapper::GetProgName(aName, SwGetPoolIdFromName::TxtColl); @@ -410,8 +422,8 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) { if (GetWrtShell()->GetSelectionType() == SelectionType::PostIt) { - auto pOLV = GetWrtShell()->GetPostItMgr()->GetActiveSidebarWin()->GetOutlinerView(); - if (auto pStyle = pOLV->GetStyleSheet()) + OutlinerView *pOLV = lcl_GetPostItOutlinerView(*GetWrtShell()); + if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr) aParam = pStyle->GetName(); } else if (auto pColl = GetWrtShell()->GetCurTextFormatColl()) @@ -1185,10 +1197,8 @@ SfxStyleFamily SwDocShell::ApplyStyles(const OUString &rName, SfxStyleFamily nFa } case SfxStyleFamily::Para: { - if (pSh->GetPostItMgr() && pSh->GetPostItMgr()->HasActiveSidebarWin()) - { - pSh->GetPostItMgr()->GetActiveSidebarWin()->GetOutlinerView()->SetStyleSheet(rName); - } + if (OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pSh)) + pOLV->SetStyleSheet(rName); else { // When outline-folding is enabled, MakeAllOutlineContentTemporarilyVisible makes