sw/qa/core/doc/data/bookmark-delete-redline.doc |binary sw/qa/core/doc/doc.cxx | 12 ++++++++++++ sw/source/core/doc/docbm.cxx | 1 + 3 files changed, 13 insertions(+)
New commits: commit 47bc36c0f87ec2d0329260bcb98d62c7667a5dd1 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Oct 24 15:03:18 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Oct 24 17:16:05 2022 +0200 sw: make sure mark container is sorted before calling equal_range() ooo89390-1.doc from crashtesting failed to export to ODT due to this. The trouble is that equal_range() needs a sorted container, but a listener may make the container unsorted. Fix the problem by re-sorting the container after calling the listener. A full ODT export is not needed to trigger the crash, it's enough to hide deletions. Change-Id: Id5601d7659d534c0bbfa84845abf0e6bb8e94c6f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141765 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/doc/data/bookmark-delete-redline.doc b/sw/qa/core/doc/data/bookmark-delete-redline.doc new file mode 100644 index 000000000000..7e46b0236b9b Binary files /dev/null and b/sw/qa/core/doc/data/bookmark-delete-redline.doc differ diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index 8087ad456105..53ac1a9e2b45 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -34,6 +34,7 @@ #include <cmdid.h> #include <unotxdoc.hxx> #include <UndoManager.hxx> +#include <IDocumentRedlineAccess.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/doc/data/"; @@ -413,6 +414,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testBookmarkDeleteListeners) xBookmark->dispose(); } +CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testBookmarkDeleteRedline) +{ + // Given a document with redlines, a mark (annotation mark) inside a redline: + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "bookmark-delete-redline.doc"); + + // When hiding deletions / showing only inserts, make sure we don't crash: + // Without the accompanying fix in place, this test would have crashed, equal_range() was used + // on an unsorted container. + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowInsert); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 65b9de1ebc13..6db0b5b51862 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1295,6 +1295,7 @@ namespace sw::mark pDdeBookmark->DeregisterFromDoc(m_rDoc); // Update aI, possibly a selection listener invalidated the iterators of m_vAllMarks. + assureSortedMarkContainers(); auto [it, endIt] = equal_range(m_vAllMarks.begin(), m_vAllMarks.end(), pMark->GetMarkStart(), CompareIMarkStartsBefore()); for (; it != endIt; ++it)