summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-03-30 11:20:12 +0200
committerAndras Timar <andras.timar@collabora.com>2022-03-30 20:46:32 +0200
commit7fdedf8a93caf292bdb643bfc9861ebc624b1929 (patch)
treeaf7c523d5e2136a563c6d05c7b944a7b9c31430f /sw
parent1c11ca079e8668bb461112f52304fc4eb786afda (diff)
sw: fix crash in SwAttrSet::CopyToModify()
Regression from commit 938a4d6624a78f3e272b3c4c07f314cb0c6db723 (tdf#128375 sw: fix copying RES_PARATR_LIST_AUTOFMT to different SwDoc, 2019-11-01), the problem is that we may get an autofmt pool item which is set, but its style handle is empty. Assume that this is the same case as having no autofmt at all. (cherry picked from commit ddfafd9b67e6e61c144b29ac73bbafb413ddf03b) Conflicts: sw/Module_sw.mk sw/source/core/attr/swatrset.cxx Change-Id: I87494fd04687d31201b4ec712cb0fb1ec7362b46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132312 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_core_attr.mk75
-rw-r--r--sw/Module_sw.mk1
-rw-r--r--sw/qa/core/attr/attr.cxx53
-rw-r--r--sw/qa/core/attr/data/attr-set.docxbin0 -> 11582 bytes
-rw-r--r--sw/source/core/attr/swatrset.cxx3
5 files changed, 131 insertions, 1 deletions
diff --git a/sw/CppunitTest_sw_core_attr.mk b/sw/CppunitTest_sw_core_attr.mk
new file mode 100644
index 000000000000..7ca0060290e3
--- /dev/null
+++ b/sw/CppunitTest_sw_core_attr.mk
@@ -0,0 +1,75 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_attr, \
+ sw/qa/core/attr/attr \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_attr, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ editeng \
+ sal \
+ sfx \
+ svl \
+ svx \
+ svxcore \
+ sw \
+ swqahelper \
+ test \
+ unotest \
+ utl \
+ vcl \
+ tl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_attr,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_attr,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_attr,\
+ udkapi \
+ offapi \
+ oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_attr))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_attr,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_attr,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_attr, \
+ modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_attr))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 05a07c427841..e883a47cf59b 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -140,6 +140,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_core_draw \
CppunitTest_sw_core_edit \
CppunitTest_sw_uibase_fldui \
+ CppunitTest_sw_core_attr \
))
ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/attr/attr.cxx b/sw/qa/core/attr/attr.cxx
new file mode 100644
index 000000000000..0df9d9ef0451
--- /dev/null
+++ b/sw/qa/core/attr/attr.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <docsh.hxx>
+#include <swdtflvr.hxx>
+#include <swmodule.hxx>
+
+namespace
+{
+constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/attr/data/";
+
+/// Covers sw/source/core/attr/ fixes.
+class Test : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet)
+{
+ // Given a document with track changes and the whole document is selected:
+ SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "attr-set.docx");
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ dispatchCommand(mxComponent, ".uno:SelectAll", {});
+ dispatchCommand(mxComponent, ".uno:Cut", {});
+ dispatchCommand(mxComponent, ".uno:SelectAll", {});
+ rtl::Reference<SwTransferable> xTransferable(new SwTransferable(*pWrtShell));
+ SwModule* pMod = SW_MOD();
+ SwTransferable* pOldTransferable = pMod->m_pXSelection;
+ pMod->m_pXSelection = xTransferable.get();
+
+ // When getting the plain text version of the selection:
+ datatransfer::DataFlavor aFlavor;
+ aFlavor.MimeType = "text/plain;charset=utf-16";
+ aFlavor.DataType = cppu::UnoType<OUString>::get();
+ uno::Any aData = xTransferable->getTransferData(aFlavor);
+
+ // Then make sure we get data without crashing:
+ CPPUNIT_ASSERT(aData.hasValue());
+ pMod->m_pXSelection = pOldTransferable;
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/attr/data/attr-set.docx b/sw/qa/core/attr/data/attr-set.docx
new file mode 100644
index 000000000000..0cb8508aa2a4
--- /dev/null
+++ b/sw/qa/core/attr/data/attr-set.docx
Binary files differ
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index dea4ccfef5aa..b0909ca8b782 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -364,7 +364,8 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const
}
if (pSrcDoc != pDstDoc &&
- SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem))
+ SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem) &&
+ pItem->StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle())
{
SfxItemSet const& rAutoStyle(*pItem->StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle());
std::shared_ptr<SfxItemSet> const pNewSet(