diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-08-23 17:13:23 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-08-23 18:35:10 +0000 |
commit | e1276f7bd5a396f23856d039f3e79e20aa8232fc (patch) | |
tree | 25e3c85cfec6b37eae970eda754995ab9eeeee2d /sw/source/filter | |
parent | 4efb0056f24698516aa5550ec926255da45a2381 (diff) |
check for bad locations
(cherry picked from commit b164d08f0c12a3434fad1b40900ddc8cb510370c)
Change-Id: I635585f664e700047d92821fb965d42b803a8a15
Reviewed-on: https://gerrit.libreoffice.org/17939
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'sw/source/filter')
-rw-r--r-- | sw/source/filter/basflt/fltshell.cxx | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/sw/source/filter/basflt/fltshell.cxx b/sw/source/filter/basflt/fltshell.cxx index 549731a2a8aa..ef46c21faad6 100644 --- a/sw/source/filter/basflt/fltshell.cxx +++ b/sw/source/filter/basflt/fltshell.cxx @@ -419,25 +419,33 @@ SwFltStackEntry* SwFltControlStack::SetAttr(const SwPosition& rPos, return pRet; } -static void MakePoint(const SwFltStackEntry& rEntry, SwDoc* pDoc, +static bool MakePoint(const SwFltStackEntry& rEntry, SwDoc* pDoc, SwPaM& rRegion) { // the anchor is the Pam's Point. It's modified when inserting // text, etc.; therefore it is kept on the stack. Only the // attribute's format needs to be set. rRegion.DeleteMark(); - rRegion.GetPoint()->nNode = rEntry.m_aMkPos.m_nNode.GetIndex() + 1; + + sal_uLong nMk = rEntry.m_aMkPos.m_nNode.GetIndex() + 1; + const SwNodes& rMkNodes = rEntry.m_aMkPos.m_nNode.GetNodes(); + if (nMk >= rMkNodes.Count()) + return false; + + rRegion.GetPoint()->nNode = nMk; SwCntntNode* pCNd = GetCntntNode(pDoc, rRegion.GetPoint()->nNode, true); rRegion.GetPoint()->nContent.Assign(pCNd, rEntry.m_aMkPos.m_nCntnt); + return true; } // MakeBookRegionOrPoint() behaves like MakeRegionOrPoint, except that // it adheres to certain restrictions on bookmarks in tables (cannot // span more than one cell) -static void MakeBookRegionOrPoint(const SwFltStackEntry& rEntry, SwDoc* pDoc, +static bool MakeBookRegionOrPoint(const SwFltStackEntry& rEntry, SwDoc* pDoc, SwPaM& rRegion, bool bCheck ) { - if (rEntry.MakeRegion(pDoc, rRegion, bCheck )){ + if (rEntry.MakeRegion(pDoc, rRegion, bCheck )) + { // sal_Bool b1 = rNds[rRegion.GetPoint()->nNode]->FindTableNode() != 0; if (rRegion.GetPoint()->nNode.GetNode().FindTableBoxStartNode() != rRegion.GetMark()->nNode.GetNode().FindTableBoxStartNode()) @@ -445,9 +453,9 @@ static void MakeBookRegionOrPoint(const SwFltStackEntry& rEntry, SwDoc* pDoc, rRegion.Exchange(); // invalid range rRegion.DeleteMark(); // -> both to mark } - }else{ - MakePoint(rEntry, pDoc, rRegion); + return true; } + return MakePoint(rEntry, pDoc, rRegion); } // IterateNumrulePiece() looks for the first range valid for Numrules @@ -596,8 +604,10 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos, break; case RES_FLTR_ANNOTATIONMARK: { - MakeBookRegionOrPoint(rEntry, pDoc, aRegion, true); - pDoc->getIDocumentMarkAccess()->makeAnnotationMark(aRegion, OUString()); + if (MakeBookRegionOrPoint(rEntry, pDoc, aRegion, true)) + pDoc->getIDocumentMarkAccess()->makeAnnotationMark(aRegion, OUString()); + else + SAL_WARN("sw", "failed to make book region or point"); } break; case RES_FLTR_TOX: |