sw/qa/filter/ascii/ascii.cxx           |   37 +++++++++++++++++++++++++++++++++
 sw/qa/filter/ascii/data/tdf162180.docx |binary
 sw/source/filter/ascii/wrtasc.cxx      |    4 ++-
 3 files changed, 40 insertions(+), 1 deletion(-)

New commits:
commit 145c606d01e0ee673dee69271477155fef6aa81b
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jul 25 13:12:09 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jul 25 21:42:00 2024 +0200

    tdf#162180: GetTableBox might return nullptr
    
    Change-Id: I31091b5bd06ba30a2e9bbddad66c5c597b22a6fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171007
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/filter/ascii/ascii.cxx b/sw/qa/filter/ascii/ascii.cxx
index db581043fb0e..bdcf1a142273 100644
--- a/sw/qa/filter/ascii/ascii.cxx
+++ b/sw/qa/filter/ascii/ascii.cxx
@@ -147,6 +147,43 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf144576_ascii)
     // left spot available
     CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf162180)
+{
+    createSwDoc("tdf162180.docx");
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // Select the whole table
+    dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
+    dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
+    dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
+
+    // Without the fix in place, this test would have crashed here
+    rtl::Reference<SwTransferable> xTransferable(new 
SwTransferable(*pWrtShell));
+    xTransferable->Copy(); // Ctl-C
+    xTransferable.get();
+
+    // Get the plain text version of the selection
+    datatransfer::DataFlavor aFlavor;
+    aFlavor.MimeType = "text/plain;charset=utf-16";
+    aFlavor.DataType = cppu::UnoType<OUString>::get();
+    uno::Any aData = xTransferable->getTransferData(aFlavor);
+    CPPUNIT_ASSERT(aData.hasValue());
+
+    OUString aActual;
+    aData >>= aActual;
+
+#if !defined(_WIN32) //FIXME
+    OUString aExpected
+        = u"2010       2011"_ustr SAL_NEWLINE_STRING u"All Projects"_ustr 
SAL_NEWLINE_STRING u"Pending "_ustr SAL_NEWLINE_STRING u"USA West    
Approved"_ustr SAL_NEWLINE_STRING u"    Central Pending"_ustr 
SAL_NEWLINE_STRING u"     East    Approved"_ustr;
+#else
+    OUString aExpected
+        = u"2010       2011"_ustr SAL_NEWLINE_STRING u"All Projects
Pending "_ustr SAL_NEWLINE_STRING u"USA West    Approved"_ustr 
SAL_NEWLINE_STRING u"    Central Pending"_ustr SAL_NEWLINE_STRING u"     East   
 Approved"_ustr;
+#endif
+
+    CPPUNIT_ASSERT_EQUAL(aExpected, aActual.trim());
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/filter/ascii/data/tdf162180.docx 
b/sw/qa/filter/ascii/data/tdf162180.docx
new file mode 100644
index 000000000000..4ac1730e275e
Binary files /dev/null and b/sw/qa/filter/ascii/data/tdf162180.docx differ
diff --git a/sw/source/filter/ascii/wrtasc.cxx 
b/sw/source/filter/ascii/wrtasc.cxx
index 39f5ec9cfb91..af08a2771c99 100644
--- a/sw/source/filter/ascii/wrtasc.cxx
+++ b/sw/source/filter/ascii/wrtasc.cxx
@@ -242,7 +242,9 @@ void SwASCWriter::WriteTable(SwTableNode* pTableNd, 
SwTextNode* pNd)
         {
             Out( aASCNodeFnTab, *pNd, *this );
 
-            Point aPrevBoxPoint = pNd->GetTableBox()->GetCoordinates();
+            Point aPrevBoxPoint;
+            if (const SwTableBox* pPrevBox = pNd->GetTableBox())
+                aPrevBoxPoint = pPrevBox->GetCoordinates();
             m_pCurrentPam->Move(fnMoveForward, GoInNode);
             pNd = m_pCurrentPam->GetPoint()->GetNode().GetTextNode();
 

Reply via email to