sw/inc/node.hxx                   |    2 +-
 sw/source/core/doc/docredln.cxx   |   11 +++++++----
 sw/source/filter/ascii/wrtasc.cxx |    9 ++++++---
 3 files changed, 14 insertions(+), 8 deletions(-)

New commits:
commit 2ed451f2b813705334923de52e802cc62f39d3ca
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jul 25 21:40:39 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Jul 31 17:37:51 2024 +0200

    sw: use SAL_RET_MAYBENULL in GetTableBox()
    
    This could have caught tdf#162180
    
    Change-Id: I71e86b402ae0c603d1c7ace209d55f5808b9ebe2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171054
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 3a961b522a82d41a0a3cd09b7fbb9bde6b79f3d8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171036
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index ec17dd6aa78c..5e968000cccf 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -307,7 +307,7 @@ public:
     SwFrameFormat* GetFlyFormat() const;
 
     /// If node is in a table return the respective table box.
-    SwTableBox* GetTableBox() const;
+    SAL_RET_MAYBENULL SwTableBox* GetTableBox() const;
 
     SwNodeOffset GetIndex() const { return SwNodeOffset(GetPos()); }
 
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 91c4c5a29bff..b16dcb3b1490 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -616,10 +616,13 @@ static void lcl_setRowNotTracked(SwNode& rNode)
     if ( rDoc.GetIDocumentUndoRedo().DoesUndo() && rNode.GetTableBox() )
     {
         SvxPrintItem aSetTracking(RES_PRINT, false);
-        SwNodeIndex aInsPos( *(rNode.GetTableBox()->GetSttNd()), 1);
-        SwCursor aCursor( SwPosition(aInsPos), nullptr );
-        ::sw::UndoGuard const undoGuard(rNode.GetDoc().GetIDocumentUndoRedo());
-        rDoc.SetRowNotTracked( aCursor, aSetTracking );
+        if (const SwTableBox* pTableBox = rNode.GetTableBox())
+        {
+            SwNodeIndex aInsPos( *(pTableBox->GetSttNd()), 1);
+            SwCursor aCursor( SwPosition(aInsPos), nullptr );
+            ::sw::UndoGuard const 
undoGuard(rNode.GetDoc().GetIDocumentUndoRedo());
+            rDoc.SetRowNotTracked( aCursor, aSetTracking );
+        }
     }
 }
 
diff --git a/sw/source/filter/ascii/wrtasc.cxx 
b/sw/source/filter/ascii/wrtasc.cxx
index af08a2771c99..6b7ada9bd87e 100644
--- a/sw/source/filter/ascii/wrtasc.cxx
+++ b/sw/source/filter/ascii/wrtasc.cxx
@@ -243,21 +243,24 @@ void SwASCWriter::WriteTable(SwTableNode* pTableNd, 
SwTextNode* pNd)
             Out( aASCNodeFnTab, *pNd, *this );
 
             Point aPrevBoxPoint;
-            if (const SwTableBox* pPrevBox = pNd->GetTableBox())
-                aPrevBoxPoint = pPrevBox->GetCoordinates();
+            const SwTableBox* pTableBox = pNd->GetTableBox();
+            if (pTableBox)
+                aPrevBoxPoint = pTableBox->GetCoordinates();
             m_pCurrentPam->Move(fnMoveForward, GoInNode);
             pNd = m_pCurrentPam->GetPoint()->GetNode().GetTextNode();
+            pTableBox = pNd->GetTableBox();
 
             // Line break in a box
             // Each line is a new SwTextNode so we
             // need to parse inside the current box
-            while (pNd->GetTableBox() && (pNd->GetTableBox()->GetCoordinates() 
== aPrevBoxPoint))
+            while (pTableBox && pTableBox->GetCoordinates() == aPrevBoxPoint)
             {
                 Strm().WriteUnicodeOrByteText(sPreLineEnd);
                 Out(aASCNodeFnTab, *pNd, *this);
 
                 m_pCurrentPam->Move(fnMoveForward, GoInNode);
                 pNd = m_pCurrentPam->GetPoint()->GetNode().GetTextNode();
+                pTableBox = pNd->GetTableBox();
             }
             if (pBox != pLine->GetTabBoxes().back())
                 Strm().WriteUChar( 0x9 );

Reply via email to