[Libreoffice-commits] core.git: Branch 'libreoffice-5-4-2' - sw/source

Michael Stahl mstahl at redhat.com
Wed Sep 27 18:00:51 UTC 2017


 sw/source/core/doc/DocumentRedlineManager.cxx |   69 +++++++++++---------------
 sw/source/core/inc/DocumentRedlineManager.hxx |    1 
 2 files changed, 31 insertions(+), 39 deletions(-)

New commits:
commit 835ccbcb594b6744683ce7248ef23548c328e4f5
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Sep 15 13:51:04 2017 +0200

    ofz#3301 sw: DeleteAndJoin found yet another way to delete new redline
    
    Not only can that happen in CompressRedlines(), it can also happen
    in the SwComparePosition::Outside case when the DeleteRedline()
    decides in particular circumstances to split up the inserted
    new redline.
    
    Arguably it's wrong to split up the new redline in this case;
    not sure if that ever happens in a legitimate use case though.
    
    Avoid this by removing the hack to temporarily insert the new redline
    and instead create a temporary SwUnoCursor that will be corrected
    on behalf of the new redline, while the new redline is parked on a
    safe node.
    
    This not only avoids the crash on this file but also makes the
    "corrupted redline table" assertions go away.
    
    Change-Id: I478f4cfc53a19d2cf2f0937f631962f80b1815ff
    Reviewed-on: https://gerrit.libreoffice.org/42407
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit aa67a58c114338e90c589e5916f94a77f89cd727)
    Reviewed-on: https://gerrit.libreoffice.org/42453
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Tested-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 90cc40202ab8..de092e9b2a0c 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -27,6 +27,7 @@
 #include <docary.hxx>
 #include <ndtxt.hxx>
 #include <comcore.hrc>
+#include <unocrsr.hxx>
 #include <swmodule.hxx>
 #include <editsh.hxx>
 #include <vcl/layout.hxx>
@@ -575,6 +576,32 @@ namespace
             }
         }
     }
+
+    /// in case some text is deleted, ensure that the not-yet-inserted
+    /// SwRangeRedline has its positions corrected not to point to deleted node
+    class TemporaryRedlineUpdater
+    {
+    private:
+        SwRangeRedline & m_rRedline;
+        std::shared_ptr<SwUnoCursor> m_pCursor;
+    public:
+        TemporaryRedlineUpdater(SwDoc & rDoc, SwRangeRedline & rRedline)
+            : m_rRedline(rRedline)
+            , m_pCursor(rDoc.CreateUnoCursor(*rRedline.GetPoint(), false))
+        {
+            if (m_rRedline.HasMark())
+            {
+                m_pCursor->SetMark();
+                *m_pCursor->GetMark() = *m_rRedline.GetMark();
+                *m_rRedline.GetMark() = SwPosition(rDoc.GetNodes().GetEndOfContent());
+            }
+            *m_rRedline.GetPoint() = SwPosition(rDoc.GetNodes().GetEndOfContent());
+        }
+        ~TemporaryRedlineUpdater()
+        {
+            static_cast<SwPaM&>(m_rRedline) = *m_pCursor;
+        }
+    };
 }
 
 namespace sw
@@ -1223,20 +1250,11 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
                             {
                                 mpRedlineTable->Remove( n );
                                 bDec = true;
-                                // We insert temporarily so that pNew is
-                                // also dealt with when moving the indices.
                                 if( bCallDelete )
                                 {
-                                    ::comphelper::FlagGuard g(m_isForbidCompressRedlines);
-                                    //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr
-                                    mpRedlineTable->Insert( pNewRedl );
+                                    TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl);
                                     m_rDoc.getIDocumentContentOperations().DeleteAndJoin( *pRedl );
-                                    if (pNewRedl && !mpRedlineTable->Remove(pNewRedl))
-                                    {
-                                        assert(false); // can't happen
-                                        pNewRedl = nullptr;
-                                    }
-                                    bCompress = true; // delayed compress
+                                    n = 0;      // re-initialize
                                 }
                                 delete pRedl;
                             }
@@ -1258,18 +1276,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
 
                                 if( bCallDelete )
                                 {
-                                    // We insert temporarily so that pNew is
-                                    // also dealt with when moving the indices.
-                                    ::comphelper::FlagGuard g(m_isForbidCompressRedlines);
-                                    //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr
-                                    mpRedlineTable->Insert( pNewRedl );
+                                    TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl);
                                     m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam );
-                                    if (pNewRedl && !mpRedlineTable->Remove(pNewRedl))
-                                    {
-                                        assert(false); // can't happen
-                                        pNewRedl = nullptr;
-                                    }
-                                    bCompress = true; // delayed compress
                                     n = 0;      // re-initialize
                                 }
                                 bDec = true;
@@ -1290,18 +1298,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall
 
                                 if( bCallDelete )
                                 {
-                                    // We insert temporarily so that pNew is
-                                    // also dealt with when moving the indices.
-                                    ::comphelper::FlagGuard g(m_isForbidCompressRedlines);
-                                    //Insert may delete pNewRedl, in which case it sets pNewRedl to nullptr
-                                    mpRedlineTable->Insert( pNewRedl );
+                                    TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl);
                                     m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam );
-                                    if (pNewRedl && !mpRedlineTable->Remove(pNewRedl))
-                                    {
-                                        assert(false); // can't happen
-                                        pNewRedl = nullptr;
-                                    }
-                                    bCompress = true; // delayed compress
                                     n = 0;      // re-initialize
                                     bDec = true;
                                 }
@@ -1796,11 +1794,6 @@ bool DocumentRedlineManager::AppendTableCellRedline( SwTableCellRedline* pNewRed
 
 void DocumentRedlineManager::CompressRedlines()
 {
-    if (m_isForbidCompressRedlines)
-    {
-        return;
-    }
-
     CHECK_REDLINE( *this )
 
     void (SwRangeRedline::*pFnc)(sal_uInt16, size_t) = nullptr;
diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx
index 2a5c1cd24d1f..785c8eac8313 100644
--- a/sw/source/core/inc/DocumentRedlineManager.hxx
+++ b/sw/source/core/inc/DocumentRedlineManager.hxx
@@ -137,7 +137,6 @@ private:
     sal_uInt16 mnAutoFormatRedlnCommentNo;  /**< SeqNo for conjoining of AutoFormat-Redlines.
                                          by the UI. Managed by SwAutoFormat! */
     css::uno::Sequence <sal_Int8 > maRedlinePasswd;
-    bool m_isForbidCompressRedlines = false;
 };
 
 }


More information about the Libreoffice-commits mailing list