sw/source/core/doc/DocumentContentOperationsManager.cxx |    2 +-
 sw/source/core/txtnode/ndtxt.cxx                        |   10 ++++++++++
 sw/source/core/txtnode/txtedt.cxx                       |    1 +
 sw/source/core/undo/undel.cxx                           |    3 ++-
 4 files changed, 14 insertions(+), 2 deletions(-)

New commits:
commit ee46457ce572649c0b5f238d2556c0cc5a7a8ead
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Aug 31 15:43:31 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 2 09:02:19 2022 +0200

    assert SwContentNodeIndex passed to SwTextNode are actually also on that 
node
    
    which flushes out a couple of bugs - unfortunately my fixes to those
    call sites are pretty much guesses
    
    Change-Id: I4b3f8a94042eef10c35112f3dc19fe214b472906
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139115
    Tested-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index a870e239514a..e28017d44aec 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -5124,7 +5124,7 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         pDestTextNd = aInsPos.GetNode().GetTextNode();
         if (pEndTextNd)
         {
-            SwContentIndex aDestIdx( rPos.nContent );
+            SwContentIndex aDestIdx( aInsPos.GetNode().GetContentNode(), 
rPos.GetContentIndex() );
             if( !pDestTextNd )
             {
                 pDestTextNd = rDoc.GetNodes().MakeTextNode( aInsPos.GetNode(),
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index ec9ce2f88756..27053fe2b99a 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1228,6 +1228,7 @@ void SwTextNode::Update(
     const sal_Int32 nChangeLen,
     UpdateMode const eMode)
 {
+    assert(rPos.GetContentNode() == this);
     SetAutoCompleteWordDirty( true );
 
     std::unique_ptr<SwpHts> pCollector;
@@ -2041,6 +2042,8 @@ void SwTextNode::CopyText( SwTextNode *const pDest,
 {
     CHECK_SWPHINTS_IF_FRM(this);
     CHECK_SWPHINTS(pDest);
+    assert(rDestStart.GetContentNode() == pDest);
+    assert(rStart.GetContentNode() == this);
     sal_Int32 nTextStartIdx = rStart.GetIndex();
     sal_Int32 nDestStart = rDestStart.GetIndex();      // remember old Pos
 
@@ -2313,6 +2316,7 @@ void SwTextNode::CopyText( SwTextNode *const pDest,
 OUString SwTextNode::InsertText( const OUString & rStr, const SwContentIndex & 
rIdx,
         const SwInsertFlags nMode )
 {
+    assert(rIdx.GetContentNode() == this);
     assert(rIdx <= m_Text.getLength()); // invalid index
 
     const sal_Int32 aPos = rIdx.GetIndex();
@@ -2447,6 +2451,9 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const 
SwContentIndex & rDest
 
     assert(pDest != this); // destination must be different node
 
+    assert(rDestStart.GetContentNode() == pDest);
+    assert(rStart.GetContentNode() == this);
+
     if( !nLen )
     {
         // if no length is given, copy attributes at position rStart
@@ -2705,6 +2712,7 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const 
SwContentIndex & rDest
 void SwTextNode::EraseText(const SwContentIndex &rIdx, const sal_Int32 nCount,
         const SwInsertFlags nMode )
 {
+    assert(rIdx.GetContentNode() == this);
     assert(rIdx <= m_Text.getLength()); // invalid index
 
     const sal_Int32 nStartIdx = rIdx.GetIndex();
@@ -3486,6 +3494,7 @@ bool SwTextNode::CopyExpandText(SwTextNode& rDestNd, 
const SwContentIndex* pDest
 {
     if( &rDestNd == this )
         return false;
+    assert(!pDestIdx || pDestIdx->GetContentNode() == &rDestNd);
 
     SwContentIndex aDestIdx(&rDestNd, rDestNd.GetText().getLength());
     if( pDestIdx )
@@ -3731,6 +3740,7 @@ OUString SwTextNode::GetRedlineText() const
 void SwTextNode::ReplaceText( const SwContentIndex& rStart, const sal_Int32 
nDelLen,
                              const OUString & rStr)
 {
+    assert(rStart.GetContentNode() == this);
     assert( rStart.GetIndex() < m_Text.getLength()     // index out of bounds
          && rStart.GetIndex() + nDelLen <= m_Text.getLength());
 
diff --git a/sw/source/core/txtnode/txtedt.cxx 
b/sw/source/core/txtnode/txtedt.cxx
index 05a830ef6082..c22601e99a8a 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -372,6 +372,7 @@ void SwTextNode::RstTextAttr(
     const bool bInclRefToxMark,
     const bool bExactRange )
 {
+    assert(rIdx.GetContentNode() == this);
     if ( !GetpSwpHints() )
         return;
 
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index 99bac98e9ffc..fab3bb4bc323 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -920,7 +920,8 @@ void SwUndoDelete::UndoImpl(::sw::UndoRedoContext & 
rContext)
             assert(pTextNd); // else where does m_aEndStr come from?
             if( pTextNd )
             {
-                OUString const ins( pTextNd->InsertText(*m_aEndStr, 
aPos.nContent,
+                SwContentIndex aTmpIdx(pTextNd, aPos.GetContentIndex());
+                OUString const ins( pTextNd->InsertText(*m_aEndStr, aTmpIdx,
                         SwInsertFlags::NOHINTEXPAND) );
                 assert(ins.getLength() == m_aEndStr->getLength()); // must 
succeed
                 (void) ins;

Reply via email to