sw/qa/extras/uiwriter/data/table-in-table.fodt |   29 +++++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter9.cxx            |   14 ++++++++++++
 sw/source/core/crsr/crsrsh.cxx                 |   12 +++++++---
 3 files changed, 52 insertions(+), 3 deletions(-)

New commits:
commit e7803234b5609d6ff66ebe79b7409d0fc822b067
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu May 2 09:11:25 2024 +0500
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu May 2 19:10:37 2024 +0200

    tdf#160898: check for nullptr
    
    Regression after commit d81379db730a163c5ff75d4f3a3cddbd7b5eddda
    (tdf#154877 sw: generalise ExtendedSelectAll(), 2023-05-09)
    
    Change-Id: I9289171647fca8bd1b696399ff7c43a2ac7b8b30
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166990
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166997
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/data/table-in-table.fodt 
b/sw/qa/extras/uiwriter/data/table-in-table.fodt
new file mode 100644
index 000000000000..e055d343b847
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/table-in-table.fodt
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:automatic-styles>
+  <style:style style:name="border" style:family="table-cell">
+   <style:table-cell-properties fo:padding="1mm" fo:border="0.5pt solid 
#000000"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:body>
+  <office:text>
+   <text:p/>
+   <table:table>
+    <table:table-column/>
+    <table:table-row>
+     <table:table-cell table:style-name="border">
+      <table:table>
+       <table:table-column/>
+       <table:table-row>
+        <table:table-cell table:style-name="border"/>
+       </table:table-row>
+      </table:table>
+      <text:p/>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+   <text:p/>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx 
b/sw/qa/extras/uiwriter/uiwriter9.cxx
index 3772955dd9c1..fe69b26dd87a 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -200,6 +200,20 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159816)
     xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, 
/*bXSelection=*/true);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf160898)
+{
+    // Given a document with a 1-cell table in another 1-cell table:
+    createSwDoc("table-in-table.fodt");
+    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDocShell* pDocShell = pXTextDocument->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+
+    // Move to the normally hidden paragraph inside the outer table cell, 
following the inner table
+    pWrtShell->Down(false, 2);
+    // Without the fix, this would crash:
+    pWrtShell->SelAll();
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index b7f6962982b5..33f11e9a282b 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -738,9 +738,15 @@ bool SwCursorShell::MoveStartText()
     SwTableNode const*const pTable(pStartNode->FindTableNode());
     m_pCurrentCursor->GetPoint()->Assign(*pStartNode);
     GetDoc()->GetNodes().GoNext(m_pCurrentCursor->GetPoint());
-    while (m_pCurrentCursor->GetPoint()->GetNode().FindTableNode() != pTable
-        && (!pTable || pTable->GetIndex() < 
m_pCurrentCursor->GetPoint()->GetNode().FindTableNode()->GetIndex())
-        && MoveOutOfTable());
+    while (auto* pFoundTable = 
m_pCurrentCursor->GetPoint()->GetNode().FindTableNode())
+    {
+        if (pFoundTable == pTable)
+            break;
+        if (pTable && pTable->GetIndex() >= pFoundTable->GetIndex())
+            break;
+        if (!MoveOutOfTable())
+            break;
+    }
     
UpdateCursor(SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE|SwCursorShell::READONLY);
     return old != *m_pCurrentCursor->GetPoint();
 }

Reply via email to