sw/qa/complex/writer/CheckTable.java | 32 +++++++++++++++++++++++++ sw/source/core/unocore/unocrsrhelper.cxx | 39 +++++++++++++++++++++---------- sw/source/core/unocore/unoobj.cxx | 4 +++ sw/source/core/unocore/unoobj2.cxx | 7 +++-- 4 files changed, 67 insertions(+), 15 deletions(-)
New commits: commit 68d40d2cae3700f4134375fcaf9649ac626ada7d Author: Michael Stahl <mst...@redhat.com> Date: Wed Jan 9 15:45:32 2013 +0100 fdo#58242: sw: fix more crashes when not on SwTxtNode In getCrsrPropertyValue etc.; also add a unit test for the problem. Change-Id: Ibd459a43393c39b4fed9fb89aae4a5f7bacff007 diff --git a/sw/qa/complex/writer/CheckTable.java b/sw/qa/complex/writer/CheckTable.java index 449dc1a..6fe9b28 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 21f553a..a1d068d 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -487,9 +487,9 @@ 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 @@ 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 f5736b8..3162e5a 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 043f0cf..62f73db 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(); commit 11b380874a36869452246cc77c392d1767e60e95 Author: Noel Power <noel.po...@suse.com> Date: Wed Jan 9 14:40:10 2013 +0100 fdo#58242: getCrsrPropertyValue: fix crashes when PaM not on SwTxtNode Change-Id: I67042b5d689457921a928454c9051f0402be17e6 diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 584b2d7..21f553a 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -292,9 +292,12 @@ bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry break; case FN_UNO_DOCUMENT_INDEX_MARK: { - ::std::vector<SwTxtAttr *> const marks( - rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt( - rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK)); + ::std::vector<SwTxtAttr *> marks; + if (rPam.GetNode()->IsTxtNode()) + { + marks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt( + rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK); + } if (marks.size()) { if( pAny ) @@ -418,9 +421,9 @@ bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry case FN_UNO_ENDNOTE: case FN_UNO_FOOTNOTE: { - SwTxtAttr *const pTxtAttr = + SwTxtAttr *const pTxtAttr = rPam.GetNode()->IsTxtNode() ? rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt( - rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN); + rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN) : 0; if(pTxtAttr) { const SwFmtFtn& rFtn = pTxtAttr->GetFtn(); @@ -442,9 +445,13 @@ bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry break; case FN_UNO_REFERENCE_MARK: { - ::std::vector<SwTxtAttr *> const marks( + ::std::vector<SwTxtAttr *> marks; + if (rPam.GetNode()->IsTxtNode()) + { + marks = ( rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt( rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK)); + } if (marks.size()) { if( pAny ) @@ -460,9 +467,10 @@ bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry break; case FN_UNO_NESTED_TEXT_CONTENT: { - uno::Reference<XTextContent> const xRet( - GetNestedTextContent(*rPam.GetNode()->GetTxtNode(), - rPam.GetPoint()->nContent.GetIndex(), false)); + uno::Reference<XTextContent> const xRet(rPam.GetNode()->IsTxtNode() + ? GetNestedTextContent(*rPam.GetNode()->GetTxtNode(), + rPam.GetPoint()->nContent.GetIndex(), false) + : 0); if (xRet.is()) { if (pAny) @@ -711,6 +719,8 @@ void getNumberingProperty(SwPaM& rPam, PropertyState& eState, Any * pAny ) void GetCurPageStyle(SwPaM& rPaM, String &rString) { + if (!rPaM.GetCntntNode()) + return; // TODO: is there an easy way to get it for tables/sections? const SwPageFrm* pPage = rPaM.GetCntntNode()->getLayoutFrm(rPaM.GetDoc()->GetCurrentLayout())->FindPageFrm(); if(pPage) SwStyleNameMapper::FillProgName( pPage->GetPageDesc()->GetName(), rString, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits