From e1e6ff49a244039bc2c2c09026ab9ca3ef96e859 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 7 Feb 2023 20:37:37 +0000 Subject: tdf#153434 crash on "new" macro with no cursor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit probably good in trunk since: commit 6e2bd11251afbe64f9889ede36b28b00f47aaff5 Date: Sun Aug 7 12:49:11 2022 +0100 tdf#150291 Revert "Fix crash when no valid EntryDescriptor found" but still visible in 7-4 Change-Id: I63898ed3e33f73f8a93528872449539c5df6574f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146645 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- basctl/source/basicide/macrodlg.cxx | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'basctl/source/basicide') diff --git a/basctl/source/basicide/macrodlg.cxx b/basctl/source/basicide/macrodlg.cxx index b1097b9ad8c8..e2511ee53b6b 100644 --- a/basctl/source/basicide/macrodlg.cxx +++ b/basctl/source/basicide/macrodlg.cxx @@ -295,7 +295,11 @@ void MacroChooser::DeleteMacro() SbMethod* MacroChooser::CreateMacro() { SbMethod* pMethod = nullptr; - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); + if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter)) + { + SAL_WARN("basctl.basicide", "neither cursor set nor root entry to use as fallback"); + return nullptr; + } EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get()); const ScriptDocument& aDocument( aDesc.GetDocument() ); OSL_ENSURE( aDocument.isAlive(), "MacroChooser::CreateMacro: no document!" ); @@ -474,8 +478,9 @@ IMPL_LINK_NOARG(MacroChooser, MacroSelectHdl, weld::TreeView&, void) IMPL_LINK_NOARG(MacroChooser, BasicSelectHdl, weld::TreeView&, void) { - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); - SbModule* pModule = m_xBasicBox->FindModule(m_xBasicBoxIter.get()); + SbModule* pModule = nullptr; + if (m_xBasicBox->get_cursor(m_xBasicBoxIter.get())) + pModule = m_xBasicBox->FindModule(m_xBasicBoxIter.get()); m_xMacroBox->clear(); if (pModule) { @@ -614,7 +619,11 @@ IMPL_LINK(MacroChooser, ButtonHdl, weld::Button&, rButton, void) } else if (&rButton == m_xEditButton.get() || &rButton == m_xDelButton.get() || &rButton == m_xNewButton.get()) { - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); + if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter)) + { + SAL_WARN("basctl.basicide", "neither cursor set nor root entry to use as fallback"); + return; + } EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get()); const ScriptDocument& aDocument( aDesc.GetDocument() ); DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" ); @@ -697,7 +706,11 @@ IMPL_LINK(MacroChooser, ButtonHdl, weld::Button&, rButton, void) } else if (&rButton == m_xAssignButton.get()) { - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); + if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter)) + { + SAL_WARN("basctl.basicide", "neither cursor set nor root entry to use as fallback"); + return; + } EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get()); const ScriptDocument& aDocument( aDesc.GetDocument() ); DBG_ASSERT( aDocument.isAlive(), "MacroChooser::ButtonHdl: no document, or document is dead!" ); @@ -724,14 +737,22 @@ IMPL_LINK(MacroChooser, ButtonHdl, weld::Button&, rButton, void) } else if (&rButton == m_xNewLibButton.get()) { - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); + if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter)) + { + SAL_WARN("basctl.basicide", "neither cursor set nor root entry to use as fallback"); + return; + } EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get()); const ScriptDocument& aDocument( aDesc.GetDocument() ); createLibImpl(m_xDialog.get(), aDocument, nullptr, m_xBasicBox.get()); } else if (&rButton == m_xNewModButton.get()) { - m_xBasicBox->get_cursor(m_xBasicBoxIter.get()); + if (!m_xBasicBox->get_cursor(m_xBasicBoxIter.get()) && !m_xBasicBox->get_iter_first(*m_xBasicBoxIter)) + { + SAL_WARN("basctl.basicide", "neither cursor set nor root entry to use as fallback"); + return; + } EntryDescriptor aDesc = m_xBasicBox->GetEntryDescriptor(m_xBasicBoxIter.get()); const ScriptDocument& aDocument( aDesc.GetDocument() ); const OUString& aLibName( aDesc.GetLibName() ); -- cgit