summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-11-01 18:51:06 +0100
committerMichael Stahl <michael.stahl@cib.de>2019-11-11 11:02:31 +0100
commit938a4d6624a78f3e272b3c4c07f314cb0c6db723 (patch)
treea12051721d98238c4075bdb7cef175ce11622c9a
parent1a7ba39e13d0a8e0ace2475bc50e1497c2928b78 (diff)
tdf#128375 sw: fix copying RES_PARATR_LIST_AUTOFMT to different SwDoc
When copying the item to a different SwDoc, the items in the nested SfxItemSet must be copied into the target SwDoc's item pool, or a use-after-free is inevitable. (regression from 5ba30f588d6e41a13d68b1461345fca7a7ca61ac) Change-Id: I7071ff6dccf2285d96f540ac556b9fa2265ddf00 Reviewed-on: https://gerrit.libreoffice.org/81911 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/source/core/attr/swatrset.cxx17
1 files changed, 17 insertions, 0 deletions
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index 14931ed3b4cf..3870d7334afe 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -26,6 +26,7 @@
#include <editeng/editeng.hxx>
#include <fmtanchr.hxx>
#include <fmtpdsc.hxx>
+#include <fmtautofmt.hxx>
#include <hintids.hxx>
#include <list.hxx>
#include <node.hxx>
@@ -395,6 +396,22 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
tmpSet->ClearItem( RES_ANCHOR );
}
+ if (pSrcDoc != pDstDoc &&
+ SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem))
+ {
+ SfxItemSet const& rAutoStyle(*static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle());
+ std::shared_ptr<SfxItemSet> const pNewSet(
+ rAutoStyle.SfxItemSet::Clone(true, &pDstDoc->GetAttrPool()));
+ SwFormatAutoFormat item(RES_PARATR_LIST_AUTOFMT);
+ // TODO: for ODF export we'd need to add it to the autostyle pool
+ item.SetStyleHandle(pNewSet);
+ if (!tmpSet)
+ {
+ tmpSet.reset(new SfxItemSet(*this));
+ }
+ tmpSet->Put(item);
+ }
+
if( tmpSet )
{
if( pCNd )