summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-01-09 15:45:32 +0100
committerMichael Stahl <mstahl@redhat.com>2013-01-09 15:57:50 +0100
commit68d40d2cae3700f4134375fcaf9649ac626ada7d (patch)
tree769a8d4e32158088725ab7d35904873ab36e8656
parent11b380874a36869452246cc77c392d1767e60e95 (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
-rw-r--r--sw/qa/complex/writer/CheckTable.java32
-rw-r--r--sw/source/core/unocore/unocrsrhelper.cxx11
-rw-r--r--sw/source/core/unocore/unoobj.cxx4
-rw-r--r--sw/source/core/unocore/unoobj2.cxx7
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 21f553a7f778..a1d068d92268 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 f5736b841fb4..3162e5a789bd 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 043f0cfe30d4..62f73db9a9ad 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();