cui/source/customize/cfg.cxx | 7 +++++-- cui/source/dialogs/SpellDialog.cxx | 3 +-- cui/source/dialogs/cuihyperdlg.cxx | 3 +-- cui/source/dialogs/hlmailtp.cxx | 3 +-- cui/source/dialogs/insdlg.cxx | 6 ++---- cui/source/dialogs/tipofthedaydlg.cxx | 3 +-- sfx2/source/appl/app.cxx | 2 +- sfx2/source/commandpopup/CommandPopup.cxx | 2 ++ sfx2/source/control/charmapcontrol.cxx | 7 +++++-- sfx2/source/control/request.cxx | 8 +++++++- 10 files changed, 26 insertions(+), 18 deletions(-)
New commits: commit 56e0b27d39e266be49fac93361944878ff763acd Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Dec 15 20:17:37 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Dec 16 09:59:06 2022 +0000 misc: 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: I2925c4fa4e2d48c1e676ffe7951e65120192517e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144277 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 2099a1b861c6..91584562a647 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -1293,8 +1293,11 @@ OUString SvxConfigPage::GetFrameWithDefaultAndIdentify( uno::Reference< frame::X _inout_rxFrame = xDesktop->getCurrentFrame(); } - if ( !_inout_rxFrame.is() && SfxViewFrame::Current() ) - _inout_rxFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); + if ( !_inout_rxFrame.is()) + { + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + _inout_rxFrame = pViewFrame->GetFrame().GetFrameInterface(); + } if ( !_inout_rxFrame.is() ) { diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx index 4ca5bcfe2d17..c01173808aa2 100644 --- a/cui/source/dialogs/SpellDialog.cxx +++ b/cui/source/dialogs/SpellDialog.cxx @@ -715,8 +715,7 @@ void SpellDialog::Close() // section - in that case, the cursor can move from the editable field to // the protected area, and the slots get disabled because of // SfxDisableFlags::SwOnProtectedCursor (see FN_SPELL_GRAMMAR_DIALOG in .sdi). - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if (pViewFrame) + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) pViewFrame->ToggleChildWindow(rParent.GetType()); } diff --git a/cui/source/dialogs/cuihyperdlg.cxx b/cui/source/dialogs/cuihyperdlg.cxx index 20c1b1e26f85..3352a7a10f5a 100644 --- a/cui/source/dialogs/cuihyperdlg.cxx +++ b/cui/source/dialogs/cuihyperdlg.cxx @@ -177,8 +177,7 @@ void SvxHpLinkDlg::Close() { if (IsClosing()) return; - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if (pViewFrame) + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) pViewFrame->ToggleChildWindow(SID_HYPERLINK_DIALOG); } diff --git a/cui/source/dialogs/hlmailtp.cxx b/cui/source/dialogs/hlmailtp.cxx index 4a099524fed5..4bee51baf721 100644 --- a/cui/source/dialogs/hlmailtp.cxx +++ b/cui/source/dialogs/hlmailtp.cxx @@ -209,8 +209,7 @@ IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, v |************************************************************************/ IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, weld::Button&, void) { - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if( pViewFrame ) + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) { SfxItemPool &rPool = pViewFrame->GetPool(); SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool); diff --git a/cui/source/dialogs/insdlg.cxx b/cui/source/dialogs/insdlg.cxx index 9e328b00cb04..53488a72e334 100644 --- a/cui/source/dialogs/insdlg.cxx +++ b/cui/source/dialogs/insdlg.cxx @@ -196,8 +196,7 @@ short SvInsertOleDlg::run() uno::Reference<task::XStatusIndicator> xProgress; OUString aProgressText; - SfxViewFrame* pFrame = SfxViewFrame::Current(); - if (pFrame) + if (SfxViewFrame* pFrame = SfxViewFrame::Current()) { // Have a current frame, create a matching progressbar, but don't start it yet. uno::Reference<frame::XFrame> xFrame @@ -302,8 +301,7 @@ short SvInsertOleDlg::run() // create object from media descriptor uno::Reference<task::XStatusIndicator> xProgress; - SfxViewFrame* pFrame = SfxViewFrame::Current(); - if (pFrame) + if (SfxViewFrame* pFrame = SfxViewFrame::Current()) { // Have a current frame, create visual indication that insert is in progress. uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface(); diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx index 607a80616359..6cfc02f90d13 100644 --- a/cui/source/dialogs/tipofthedaydlg.cxx +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -157,8 +157,7 @@ void TipOfTheDayDialog::UpdateTip() { m_pLink->set_visible(false); //show the link only if the UNO command is available in the current module - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - if (pViewFrame) + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) { const auto xFrame = pViewFrame->GetFrame().GetFrameInterface(); const css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider( commit 4a998d9eea012896d4a5d256048407a766fc0bbd Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Dec 15 20:00:26 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Dec 16 09:58:56 2022 +0000 sfx2: check SfxViewFrame::Current() these ones look potentially worth backporting Change-Id: I9391f266b08e3842f9686db6113b61fa814f3fbb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144276 Tested-by: Caolán McNamara <caol...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx index 4b5adbdf8a2b..3d3adb84bfe4 100644 --- a/sfx2/source/appl/app.cxx +++ b/sfx2/source/appl/app.cxx @@ -410,7 +410,7 @@ IMPL_STATIC_LINK( SfxApplication, GlobalBasicErrorHdl_Impl, StarBASIC*, pStarBas const SfxViewFrame* pViewFrame = SfxViewFrame::Current(); std::shared_ptr<weld::MessageDialog> xBox; xBox.reset(Application::CreateMessageDialog( - pViewFrame->GetFrameWeld(), + pViewFrame ? pViewFrame->GetFrameWeld() : nullptr, VclMessageType::Error, VclButtonsType::Ok, aError, diff --git a/sfx2/source/commandpopup/CommandPopup.cxx b/sfx2/source/commandpopup/CommandPopup.cxx index 47df143a889b..f4cdf92436c7 100644 --- a/sfx2/source/commandpopup/CommandPopup.cxx +++ b/sfx2/source/commandpopup/CommandPopup.cxx @@ -152,6 +152,8 @@ void MenuContentHandler::addCommandIfPossible( return; auto* pViewFrame = SfxViewFrame::Current(); + if (!pViewFrame) + return; SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(pViewFrame); const SfxSlot* pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path); diff --git a/sfx2/source/control/charmapcontrol.cxx b/sfx2/source/control/charmapcontrol.cxx index 032306b8a85f..a79da745be26 100644 --- a/sfx2/source/control/charmapcontrol.cxx +++ b/sfx2/source/control/charmapcontrol.cxx @@ -207,8 +207,11 @@ IMPL_LINK_NOARG(SfxCharmapCtrl, OpenDlgHdl, weld::Button&, void) { m_xControl->EndPopupMode(); - uno::Reference<frame::XFrame> xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); - comphelper::dispatchCommand(".uno:InsertSymbol", xFrame, {}); + if (SfxViewFrame* pViewFrm = SfxViewFrame::Current()) + { + uno::Reference<frame::XFrame> xFrame = pViewFrm->GetFrame().GetFrameInterface(); + comphelper::dispatchCommand(".uno:InsertSymbol", xFrame, {}); + } } void SfxCharmapCtrl::GrabFocus() diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx index 964a256b19a7..b43d1dd991bc 100644 --- a/sfx2/source/control/request.cxx +++ b/sfx2/source/control/request.cxx @@ -687,8 +687,14 @@ css::uno::Reference< css::frame::XDispatchRecorder > SfxRequest::GetMacroRecorde { css::uno::Reference< css::frame::XDispatchRecorder > xRecorder; + if (!pView) + pView = SfxViewFrame::Current(); + + if (!pView) + return xRecorder; + css::uno::Reference< css::beans::XPropertySet > xSet( - (pView ? pView : SfxViewFrame::Current())->GetFrame().GetFrameInterface(), + pView->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY); if(xSet.is())