cui/source/customize/CustomNotebookbarGenerator.cxx | 13 ++++++++----- desktop/source/lib/init.cxx | 12 ++++++++---- sd/source/ui/docshell/docshel4.cxx | 15 +++++++++------ sd/source/ui/docshell/docshell.cxx | 4 +--- sd/source/ui/func/fuexecuteinteraction.cxx | 11 ++++++----- sd/source/ui/slideshow/slideshowimpl.cxx | 3 +-- sd/source/ui/view/drviews2.cxx | 3 +-- 7 files changed, 34 insertions(+), 27 deletions(-)
New commits: commit 4a9c9488ee918879e89751a15f3ef0fcbbcd2070 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Dec 15 20:25:27 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Dec 16 10:23:20 2022 +0000 sd: check SfxViewFrame::Current() SfxViewFrame::Current() is a festering wound, these ones look like they were safe anyway, so no need to backport. But with enough checked static analysis will kick in to flag new unchecked ones. Change-Id: Ife81c0e5fc508d8eb30808884c61b8e8c6723890 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144279 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx index 13b08deafa1a..99d6890fe1f0 100644 --- a/sd/source/ui/docshell/docshel4.cxx +++ b/sd/source/ui/docshell/docshel4.cxx @@ -851,12 +851,14 @@ void DrawDocShell::GotoBookmark(std::u16string_view rBookmark) } } - SfxBindings& rBindings = ((pDrawViewShell && pDrawViewShell->GetViewFrame()!=nullptr) + if (SfxViewFrame* pViewFrame = (pDrawViewShell && pDrawViewShell->GetViewFrame()) ? pDrawViewShell->GetViewFrame() - : SfxViewFrame::Current() )->GetBindings(); - - rBindings.Invalidate(SID_NAVIGATOR_STATE, true); - rBindings.Invalidate(SID_NAVIGATOR_PAGENAME); + : SfxViewFrame::Current()) + { + SfxBindings& rBindings = pViewFrame->GetBindings(); + rBindings.Invalidate(SID_NAVIGATOR_STATE, true); + rBindings.Invalidate(SID_NAVIGATOR_PAGENAME); + } } /** @@ -964,7 +966,8 @@ void DrawDocShell::OpenBookmark( const OUString& rBookmarkURL ) SfxStringItem aStrItem( SID_FILE_NAME, rBookmarkURL ); SfxStringItem aReferer( SID_REFERER, GetMedium()->GetName() ); const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, nullptr }; - ( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs ); + if (SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current()) + pFrame->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs ); } std::shared_ptr<SfxDocumentInfoDialog> DrawDocShell::CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet &rSet) diff --git a/sd/source/ui/docshell/docshell.cxx b/sd/source/ui/docshell/docshell.cxx index 78279687a039..d837092eba68 100644 --- a/sd/source/ui/docshell/docshell.cxx +++ b/sd/source/ui/docshell/docshell.cxx @@ -336,9 +336,7 @@ void DrawDocShell::GetState(SfxItemSet &rSet) nWhich = aIter.NextWhich(); } - SfxViewFrame* pFrame = SfxViewFrame::Current(); - - if (pFrame) + if (SfxViewFrame* pFrame = SfxViewFrame::Current()) { if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN) { diff --git a/sd/source/ui/func/fuexecuteinteraction.cxx b/sd/source/ui/func/fuexecuteinteraction.cxx index d1956fcf5603..6dacef089d56 100644 --- a/sd/source/ui/func/fuexecuteinteraction.cxx +++ b/sd/source/ui/func/fuexecuteinteraction.cxx @@ -183,15 +183,16 @@ void FuExecuteInteraction::DoExecute(SfxRequest&) if (INetProtocol::File == aURL.GetProtocol()) { - SfxStringItem aUrl(SID_FILE_NAME, - aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); - SfxBoolItem aBrowsing(SID_BROWSE, true); + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + { + SfxStringItem aUrl(SID_FILE_NAME, + aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); + SfxBoolItem aBrowsing(SID_BROWSE, true); - SfxViewFrame* pViewFrm = SfxViewFrame::Current(); - if (pViewFrm) pViewFrm->GetDispatcher()->ExecuteList( SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, { &aUrl, &aBrowsing }); + } } } break; diff --git a/sd/source/ui/slideshow/slideshowimpl.cxx b/sd/source/ui/slideshow/slideshowimpl.cxx index aa815be59ffa..9e0db0948ba4 100644 --- a/sd/source/ui/slideshow/slideshowimpl.cxx +++ b/sd/source/ui/slideshow/slideshowimpl.cxx @@ -1499,8 +1499,7 @@ void SlideshowImpl::click( const Reference< XShape >& xShape ) SfxStringItem aUrl( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); SfxBoolItem aBrowsing( SID_BROWSE, true ); - SfxViewFrame* pViewFrm = SfxViewFrame::Current(); - if (pViewFrm) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { SfxUnoFrameItem aDocFrame(SID_FILLFRAME, pViewFrm->GetFrame().GetFrameInterface()); pViewFrm->GetDispatcher()->ExecuteList( SID_OPENDOC, diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index d197852c9026..ebd99d6a61b8 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -2287,8 +2287,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, false ); SfxBoolItem aBrowsing( SID_BROWSE, true ); - SfxViewFrame* pViewFrm = SfxViewFrame::Current(); - if (pViewFrm) + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) { pViewFrm->GetDispatcher()->ExecuteList(SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, commit 70e2383eaad96c8a6079613d9924063f41880724 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Dec 15 20:15:45 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Dec 16 10:23:09 2022 +0000 misc: check SfxViewFrame::Current() these ones look potentially worth backporting Change-Id: Ie01c0b598c3408f4766318267de8438e997dd1a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144278 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/cui/source/customize/CustomNotebookbarGenerator.cxx b/cui/source/customize/CustomNotebookbarGenerator.cxx index 9fb71562160a..bae85525ebd6 100644 --- a/cui/source/customize/CustomNotebookbarGenerator.cxx +++ b/cui/source/customize/CustomNotebookbarGenerator.cxx @@ -74,11 +74,14 @@ static OUString lcl_getAppName(vcl::EnumContext::Application eApp) static OUString getAppNameRegistryPath() { vcl::EnumContext::Application eApp = vcl::EnumContext::Application::Any; - const Reference<frame::XFrame>& xFrame - = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); - const Reference<frame::XModuleManager> xModuleManager - = frame::ModuleManager::create(::comphelper::getProcessComponentContext()); - eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { + const Reference<frame::XFrame>& xFrame = pViewFrame->GetFrame().GetFrameInterface(); + const Reference<frame::XModuleManager> xModuleManager + = frame::ModuleManager::create(::comphelper::getProcessComponentContext()); + eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + } OUString sAppName(lcl_getAppName(eApp)); return "org.openoffice.Office.UI.ToolbarMode/Applications/" + sAppName; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 19937da00d6d..22efa304865a 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -792,6 +792,10 @@ void ExecuteMarginULChange( // Main function which toggles page orientation of the Writer doc. Needed by ToggleOrientation void ExecuteOrientationChange() { + SfxViewFrame* pViewFrm = SfxViewFrame::Current(); + if (!pViewFrm) + return; + std::unique_ptr<SvxPageItem> pPageItem(new SvxPageItem(SID_ATTR_PAGE)); // 1mm in twips rounded @@ -799,22 +803,22 @@ void ExecuteOrientationChange() constexpr tools::Long MINBODY = o3tl::toTwips(1, o3tl::Length::mm); css::uno::Reference< css::document::XUndoManager > mxUndoManager( - getUndoManager( SfxViewFrame::Current()->GetFrame().GetFrameInterface() ) ); + getUndoManager( pViewFrm->GetFrame().GetFrameInterface() ) ); if ( mxUndoManager.is() ) mxUndoManager->enterUndoContext( "" ); const SvxSizeItem* pSizeItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pSizeItem); + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pSizeItem); std::unique_ptr<SvxSizeItem> pPageSizeItem(pSizeItem->Clone()); const SvxLongLRSpaceItem* pLRSpaceItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pLRSpaceItem); + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pLRSpaceItem); std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem(pLRSpaceItem->Clone()); const SvxLongULSpaceItem* pULSpaceItem; - SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pULSpaceItem); + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pULSpaceItem); std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem(pULSpaceItem->Clone()); {