diff options
author | Henry Castro <hcastro@collabora.com> | 2020-12-04 17:00:51 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2021-04-09 11:54:59 +0200 |
commit | d07e21ba5ff2d296cf86c20a37b59dae368773dd (patch) | |
tree | 51b5b5ca2f176afe0a5b4f9489e691d8e9f758d0 | |
parent | d560e0c16a04e509d94664b3e3a95c79a0fd41d8 (diff) |
lok: jsdialog: fix possible nullptr dereference
p = nullptr;
if (p)
{
}
p->Somenthing();
Change-Id: I2a46d6a8e7eae96928210c8941ec71eed88bf631
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107245
Tested-by: Jenkins
Reviewed-by: Henry Castro <hcastro@collabora.com>
-rw-r--r-- | vcl/jsdialog/jsdialogbuilder.cxx | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index bcf65b1ea255..b761d5b80312 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -383,33 +383,35 @@ VclPtr<vcl::Window>& JSInstanceBuilder::GetNotifierWindow() std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& id) { + std::unique_ptr<weld::Dialog> pRet; ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id); - m_nWindowId = pDialog->GetLOKWindowId(); - pDialog->SetLOKTunnelingState(false); - - InsertWindowToMap(m_nWindowId); if (pDialog) { + m_nWindowId = pDialog->GetLOKWindowId(); + pDialog->SetLOKTunnelingState(false); + + InsertWindowToMap(m_nWindowId); + assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed"); m_aOwnedToplevel.set(pDialog); m_xBuilder->drop_ownership(pDialog); m_bHasTopLevelDialog = true; - } - std::unique_ptr<weld::Dialog> pRet(pDialog ? new JSDialog(m_aOwnedToplevel, m_aOwnedToplevel, - pDialog, this, false, m_sTypeOfJSON) - : nullptr); + pRet.reset(pDialog ? new JSDialog(m_aOwnedToplevel, m_aOwnedToplevel, pDialog, this, false, + m_sTypeOfJSON) + : nullptr); - RememberWidget("__DIALOG__", pRet.get()); + RememberWidget("__DIALOG__", pRet.get()); - const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier(); - if (pNotifier && id != "MacroSelectorDialog") - { - tools::JsonWriter aJsonWriter; - m_aOwnedToplevel->DumpAsPropertyTree(aJsonWriter); - aJsonWriter.put("id", m_aOwnedToplevel->GetLOKWindowId()); - pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, aJsonWriter.extractData()); + const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier(); + if (pNotifier && id != "MacroSelectorDialog") + { + tools::JsonWriter aJsonWriter; + m_aOwnedToplevel->DumpAsPropertyTree(aJsonWriter); + aJsonWriter.put("id", m_aOwnedToplevel->GetLOKWindowId()); + pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, aJsonWriter.extractData()); + } } return pRet; |