diff options
author | Michael Stahl <mstahl@redhat.com> | 2013-01-09 15:45:32 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2013-01-09 16:02:39 +0100 |
commit | 23e5bce572ebb65b302c139e89890e23a27a994d (patch) | |
tree | 8303c30389e7d927ff0903a71443e6b70efbf645 | |
parent | 9d1cdb4f42c3fee9f24020404ce8e3d378cb34f4 (diff) |
fdo#58242: sw: fix more crashes when not on SwTxtNode
In getCrsrPropertyValue etc.; also add a unit test for the problem.
Change-Id: Ibd459a43393c39b4fed9fb89aae4a5f7bacff007
(cherry picked from commit 68d40d2cae3700f4134375fcaf9649ac626ada7d)
Signed-off-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | sw/qa/complex/writer/CheckTable.java | 32 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 11 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 7 |
4 files changed, 48 insertions, 6 deletions
diff --git a/sw/qa/complex/writer/CheckTable.java b/sw/qa/complex/writer/CheckTable.java index 449dc1ad45da..6fe9b28034d4 100644 --- a/sw/qa/complex/writer/CheckTable.java +++ b/sw/qa/complex/writer/CheckTable.java @@ -10,12 +10,16 @@ package complex.writer; import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.RuntimeException; import com.sun.star.uno.XComponentContext; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.Property; import com.sun.star.text.XText; import com.sun.star.text.XTextDocument; import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextRange; import com.sun.star.text.XTextTable; import com.sun.star.table.TableBorder; import com.sun.star.table.TableBorder2; @@ -258,6 +262,34 @@ public class CheckTable assertTrue(border2.IsDistanceValid); assertEquals(97, border2.Distance); } + + @Test + public void test_fdo58242() throws Exception + { + // insert table + XMultiServiceFactory xDocF = + UnoRuntime.queryInterface(XMultiServiceFactory.class, m_xDoc); + XTextTable xTable = UnoRuntime.queryInterface(XTextTable.class, + xDocF.createInstance("com.sun.star.text.TextTable")); + xTable.initialize(3, 3); + XText xText = m_xDoc.getText(); + XTextCursor xCursor = xText.createTextCursor(); + xText.insertTextContent(xCursor, xTable, false); + // get anchor + XTextRange xAnchor = xTable.getAnchor(); + // check all properties on the anchor - shouldn't crash despite + // pointing to a non-SwTxtNode + XPropertySet xProps = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xAnchor); + XPropertySetInfo xPropsInfo = xProps.getPropertySetInfo(); + Property[] props = xPropsInfo.getProperties(); + for (int i = 0; i < props.length; ++i) + { + try { + xProps.getPropertyValue(props[i].Name); + } catch (RuntimeException e) { } + } + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index fbe46b9a208d..4f13e2564a2d 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -487,9 +487,9 @@ sal_Bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry case FN_UNO_CHARFMT_SEQUENCE: { - SwTxtNode* pTxtNode; - if((pTxtNode = (SwTxtNode*)rPam.GetNode( sal_True )) == rPam.GetNode(sal_False) && - pTxtNode->GetpSwpHints()) + SwTxtNode *const pTxtNode = rPam.GetNode()->GetTxtNode(); + if (rPam.GetNode(sal_True) == rPam.GetNode(sal_False) + && pTxtNode && pTxtNode->GetpSwpHints()) { sal_uInt16 nPaMStart = rPam.GetPoint()->nContent.GetIndex(); sal_uInt16 nPaMEnd = rPam.GetMark() ? rPam.GetMark()->nContent.GetIndex() : nPaMStart; @@ -940,6 +940,11 @@ sal_Bool DocInsertStringSplitCR( xub_StrLen nStartIdx = 0; SwTxtNode* const pTxtNd = rNewCursor.GetPoint()->nNode.GetNode().GetTxtNode(); + if (!pTxtNd) + { + SAL_INFO("sw.uno", "DocInsertStringSplitCR: need a text node"); + return false; + } const xub_StrLen nMaxLength = ( pTxtNd ) ? STRING_LEN - pTxtNd->GetTxt().Len() : STRING_LEN; diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index a91286aecda7..62fca0543e56 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -529,6 +529,10 @@ throw (lang::IllegalArgumentException) { // multi selection is not considered SwTxtNode *const pTxtNd = rPam.GetNode()->GetTxtNode(); + if (!pTxtNd) + { + throw lang::IllegalArgumentException(); + } if (FN_UNO_NUM_LEVEL == rEntry.nWID) { sal_Int16 nLevel = 0; diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index efa650eaaf48..956a6766f2e9 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1839,9 +1839,10 @@ lcl_FillFrame(SwClient & rEnum, SwUnoCrsr& rUnoCrsr, FrameDependList_t & rFrames) { // search for objects at the cursor - anchored at/as char - SwTxtAttr const*const pTxtAttr = - rUnoCrsr.GetNode()->GetTxtNode()->GetTxtAttrForCharAt( - rUnoCrsr.GetPoint()->nContent.GetIndex(), RES_TXTATR_FLYCNT); + SwTxtAttr const*const pTxtAttr = (rUnoCrsr.GetNode()->IsTxtNode()) + ? rUnoCrsr.GetNode()->GetTxtNode()->GetTxtAttrForCharAt( + rUnoCrsr.GetPoint()->nContent.GetIndex(), RES_TXTATR_FLYCNT) + : 0; if (pTxtAttr) { const SwFmtFlyCnt& rFlyCnt = pTxtAttr->GetFlyCnt(); |