summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-03-22 21:03:15 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-03-23 15:15:30 +0100
commitac1056f9d9a922660b84f20ea86e5aabbe0e8716 (patch)
tree14e5391d14ee0b9b4f7919d0d7bb9a4c5392a47c /sw
parent5a90e1bd01044843ee78b3e43ae79b4c4fb6c07e (diff)
tdf#133933 sw: fix crash on undo of redlined pasted table
This is just a crash fix, there is some deeper problem here around undo: once redlining is on, overwriting table content during paste does not delete the fly frames anchored to empty cells (see lcl_CpyBox()), and we have the same problem on undo as well (see SwUndoTableCpyTable::UndoImpl()). And node indexes are recorded before inserting flys, so if they are not deleted, then the indexes don't match. Change-Id: I419e96c4d64f70a582358cab3808cea8b0e36649 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112939 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit 140192fd5a2fc5e9d250d077d00bcebc014f7cbf) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112810 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/undo/data/table-copy-redline.odtbin0 -> 32554 bytes
-rw-r--r--sw/qa/core/undo/undo.cxx19
-rw-r--r--sw/source/core/undo/untbl.cxx10
3 files changed, 28 insertions, 1 deletions
diff --git a/sw/qa/core/undo/data/table-copy-redline.odt b/sw/qa/core/undo/data/table-copy-redline.odt
new file mode 100644
index 000000000000..f391687823aa
--- /dev/null
+++ b/sw/qa/core/undo/data/table-copy-redline.odt
Binary files differ
diff --git a/sw/qa/core/undo/undo.cxx b/sw/qa/core/undo/undo.cxx
index e43d154f3a66..6aacac27aa68 100644
--- a/sw/qa/core/undo/undo.cxx
+++ b/sw/qa/core/undo/undo.cxx
@@ -84,6 +84,25 @@ CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testTextboxCutUndo)
CPPUNIT_ASSERT_EQUAL(pIndex1->GetIndex(), pIndex2->GetIndex());
}
+CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testTableCopyRedline)
+{
+ // Given a document with two table cells and redlining enabled:
+ load(DATA_DIRECTORY, "table-copy-redline.odt");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDocShell* pDocShell = pTextDoc->GetDocShell();
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+
+ // When doing select-all, copy, paste and undo:
+ pWrtShell->SelAll();
+ rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell);
+ pTransfer->Copy();
+ TransferableDataHelper aHelper(pTransfer.get());
+ SwTransferable::Paste(*pWrtShell, aHelper);
+
+ // Without the accompanying fix in place, this test would have crashed.
+ pWrtShell->Undo();
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 85a797d5f509..d3cf5d465d01 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -2328,7 +2328,15 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( !pTableNd )
pTableNd = pSNd->FindTableNode();
- SwTableBox& rBox = *pTableNd->GetTable().GetTableBox( nSttPos );
+ SwTableBox* pBox = pTableNd->GetTable().GetTableBox( nSttPos );
+ if (!pBox)
+ {
+ SAL_WARN("sw.core",
+ "SwUndoTableCpyTable::UndoImpl: invalid start node index for table box");
+ continue;
+ }
+
+ SwTableBox& rBox = *pBox;
SwNodeIndex aInsIdx( *rBox.GetSttNd(), 1 );
rDoc.GetNodes().MakeTextNode( aInsIdx, rDoc.GetDfltTextFormatColl() );