summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2012-08-02 12:05:06 +0200
committerPetr Mladek <pmladek@suse.cz>2012-08-02 15:38:28 +0200
commit0e79ad05e76bed420383156aaafcad08d5e34fa8 (patch)
treefaaf9284d7b3fcd1f56edfb8043696358648b46f /sw
parentd5345bfb40d6e33087fd053cc220308a2bc2945e (diff)
some tweaks in RTF filter
Signed-off-by: Petr Mladek <pmladek@suse.cz>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/doc/docnum.cxx8
-rw-r--r--sw/source/filter/rtf/rtffld.cxx19
-rw-r--r--sw/source/filter/rtf/rtffly.cxx8
-rw-r--r--sw/source/filter/rtf/rtftbl.cxx24
-rw-r--r--sw/source/filter/rtf/swparrtf.cxx7
-rw-r--r--sw/source/filter/rtf/swparrtf.hxx1
6 files changed, 43 insertions, 24 deletions
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 7caae4dd4ad7..8dae5d897626 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -89,6 +89,9 @@ namespace {
}
}
+#include <stdlib.h>
+
+
inline sal_uInt8 GetUpperLvlChg( sal_uInt8 nCurLvl, sal_uInt8 nLevel, sal_uInt16 nMask )
{
if( 1 < nLevel )
@@ -2164,6 +2167,11 @@ SwNumRule* SwDoc::FindNumRulePtr( const String& rName ) const
void SwDoc::AddNumRule(SwNumRule * pRule)
{
+ if ((SAL_MAX_UINT16 - 1) <= pNumRuleTbl->size())
+ {
+ OSL_ENSURE(false, "SwDoc::AddNumRule: table full.");
+ abort(); // this should never happen on real documents
+ }
pNumRuleTbl->push_back(pRule);
maNumRuleMap[pRule->GetName()] = pRule;
pRule->SetNumRuleMap(&maNumRuleMap);
diff --git a/sw/source/filter/rtf/rtffld.cxx b/sw/source/filter/rtf/rtffld.cxx
index 5886fcf1bf61..95dead0d5af6 100644
--- a/sw/source/filter/rtf/rtffld.cxx
+++ b/sw/source/filter/rtf/rtffld.cxx
@@ -156,7 +156,10 @@ static RTF_FLD_TYPES _WhichFld( String& rName, String& rNext )
{
rName = rName.Copy( nFndPos, static_cast< xub_StrLen >(nLen) );
nFndPos += nTokenStt + static_cast< xub_StrLen >(nLen);
- while( rNext.GetChar( nFndPos ) == ' ' ) ++nFndPos;
+ while ((nFndPos < rNext.Len()) && (rNext.GetChar(nFndPos) == ' '))
+ {
+ ++nFndPos;
+ }
rNext.Erase( 0, nFndPos );
rNext = comphelper::string::stripEnd(rNext, ' ');
return aFldNmArr[n].eFldType;
@@ -388,8 +391,10 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
{
xub_StrLen nStartDel = nPos;
nPos += 2;
- while (aSaveStr.GetChar(nPos) == ' ')
+ while ((nPos < aSaveStr.Len()) && (aSaveStr.GetChar(nPos) == ' '))
+ {
++nPos;
+ }
if (aSaveStr.EqualsIgnoreCaseAscii("MERGEFORMAT", nPos, 11))
{
xub_StrLen nNoDel = (nPos + 11 ) - nStartDel;
@@ -431,7 +436,9 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
if( STRING_NOTFOUND != ( nPos = aSaveStr.SearchAscii( "\\*" )) )
{
nPos += 2;
- while( aSaveStr.GetChar(nPos) == ' ' ) nPos++;
+ while ((nPos < aSaveStr.Len()) &&
+ (aSaveStr.GetChar(nPos) == ' '))
+ { nPos++; }
aSaveStr.Erase( 0, nPos );
// steht jetzt geanu auf dem Format-Namen
@@ -450,7 +457,9 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
if( STRING_NOTFOUND != ( nPos = aSaveStr.SearchAscii( "\\*" )) )
{
nPos += 2;
- while( aSaveStr.GetChar(nPos) == ' ' ) nPos++;
+ while ((nPos < aSaveStr.Len()) &&
+ (aSaveStr.GetChar(nPos) == ' '))
+ { nPos++; }
aSaveStr.Erase( 0, nPos );
// steht jetzt geanu auf dem Format-Namen
@@ -530,7 +539,7 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr )
// werden:
// \\data -> Datenbank-Name als Field
// DATA -> Datenbank-Info
- sal_Bool bField = rFieldStr.GetChar( 0 ) != 'D';
+ bool const bField = rFieldStr.Len() && rFieldStr.GetChar(0) != 'D';
// nur der Name interressiert
if( STRING_NOTFOUND != (nPos = aSaveStr.Search( '.' )) )
diff --git a/sw/source/filter/rtf/rtffly.cxx b/sw/source/filter/rtf/rtffly.cxx
index e31d4d3d1bd2..7876c16c9c5b 100644
--- a/sw/source/filter/rtf/rtffly.cxx
+++ b/sw/source/filter/rtf/rtffly.cxx
@@ -274,7 +274,8 @@ void SwRTFParser::SetFlysInDoc()
// liegt Ende und Start vom Naechsten im gleichen Node, dann muss
// gesplittet werden
- if( n + 1 < (sal_uInt16)aFlyArr.size() && pFlySave->nEndCnt &&
+ if (((static_cast<size_t>(n) + 1) < aFlyArr.size()) &&
+ pFlySave->nEndCnt &&
pFlySave->nEndNd == aFlyArr[ n + 1 ]->nSttNd )
{
SwCntntNode *const pCNd = pFlySave->nEndNd.GetNode().GetCntntNode();
@@ -1226,6 +1227,10 @@ void SwRTFParser::InsPicture( const String& rGrfNm, const Graphic* pGrf,
// #i83368# - Assure that graphic node is enclosed by fly frame node.
if ( bReadSwFly && !mbReadCellWhileReadSwFly )
{
+ OSL_ENSURE(!aFlyArr.empty(),
+ "SwRTFParser::InsPicture: fly array empty.");
+ if (!aFlyArr.empty())
+ {
// erzeuge nur einen normalen GrafikNode und ersetze diesen gegen
// den vorhandenen Textnode
SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
@@ -1246,6 +1251,7 @@ void SwRTFParser::InsPicture( const String& rGrfNm, const Graphic* pGrf,
if( pFlySave->nEndNd == rIdx )
pFlySave->nEndNd = rIdx.GetIndex() - 1;
}
+ }
}
else
{
diff --git a/sw/source/filter/rtf/rtftbl.cxx b/sw/source/filter/rtf/rtftbl.cxx
index 1aa7071765e0..5266b565b3da 100644
--- a/sw/source/filter/rtf/rtftbl.cxx
+++ b/sw/source/filter/rtf/rtftbl.cxx
@@ -194,6 +194,11 @@ void SwRTFParser::ReadTable( int nToken )
sal_Int16 eVerOrient = text::VertOrientation::NONE;
long nLineHeight = 0;
+ if (aMergeBoxes.empty()) // can this actually happen?
+ {
+ OSL_ASSERT(false);
+ aMergeBoxes.push_back(sal_False);
+ }
SwBoxFrmFmts aBoxFmts;
SwTableBoxFmt* pBoxFmt = pDoc->MakeTableBoxFmt();
SvxFrameDirection eDir = FRMDIR_HORI_LEFT_TOP;
@@ -283,8 +288,11 @@ void SwRTFParser::ReadTable( int nToken )
{
--m_nCurrentBox;
}
- pFmt = static_cast<SwTableBoxFmt*>(
- pLine->GetTabBoxes()[ m_nCurrentBox ]->GetFrmFmt());
+ if (m_nCurrentBox < pLine->GetTabBoxes().size())
+ {
+ pFmt = static_cast<SwTableBoxFmt*>(
+ pLine->GetTabBoxes()[m_nCurrentBox]->GetFrmFmt());
+ }
}
else
pFmt = aBoxFmts.back();
@@ -553,12 +561,6 @@ void SwRTFParser::ReadTable( int nToken )
pOldTblNd = pTableNode;
bNewTbl = sal_False;
-
- {
- //TabellenUmrandungen optimieren
- void* p = pFmt;
- aTblFmts.Insert( p, aTblFmts.Count() );
- }
}
else
{
@@ -653,12 +655,6 @@ void SwRTFParser::ReadTable( int nToken )
m_nCurrentBox = 0;
pOldTblNd = pTableNode;
-
- {
- // TabellenUmrandungen optimieren
- void* p = pFmt;
- aTblFmts.Insert( p, aTblFmts.Count() );
- }
}
}
diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx
index 94569405d4d8..95ca3ddb7009 100644
--- a/sw/source/filter/rtf/swparrtf.cxx
+++ b/sw/source/filter/rtf/swparrtf.cxx
@@ -232,7 +232,6 @@ SwRTFParser::SwRTFParser(SwDoc* pD,
maCharStyleMapper(*pD),
maSegments(*this),
maInsertedTables(*pD),
- aTblFmts(0),
mpBookmarkStart(0),
mpRedlineStack(0),
pGrfAttrSet(0),
@@ -599,7 +598,9 @@ bool rtfSections::SetCols(SwFrmFmt &rFmt, const rtfSection &rSection,
{
aCol._SetOrtho(false);
sal_uInt16 nWishWidth = 0, nHalfPrev = 0;
- for(sal_uInt16 n=0, i=0; n < rSection.maPageInfo.maColumns.size() && i < nCols; n += 2, ++i )
+ for (sal_uInt16 n=0, i=0;
+ (static_cast<size_t>(n)+1) < rSection.maPageInfo.maColumns.size() && i < nCols;
+ n += 2, ++i)
{
SwColumn* pCol = &aCol.GetColumns()[ i ];
pCol->SetLeft( nHalfPrev );
@@ -2752,7 +2753,7 @@ sal_Bool lcl_SetFmtCol( SwFmt& rFmt, sal_uInt16 nCols, sal_uInt16 nColSpace,
{
aCol._SetOrtho( sal_False );
sal_uInt16 nWishWidth = 0, nHalfPrev = 0;
- for( sal_uInt16 n = 0, i = 0; n < rColumns.size(); n += 2, ++i )
+ for (sal_uInt16 n = 0, i = 0; static_cast<size_t>(n+1) < rColumns.size(); n += 2, ++i)
{
SwColumn* pCol = &aCol.GetColumns()[ i ];
pCol->SetLeft( nHalfPrev );
diff --git a/sw/source/filter/rtf/swparrtf.hxx b/sw/source/filter/rtf/swparrtf.hxx
index 8d06a9cbaac0..e8238cd1b409 100644
--- a/sw/source/filter/rtf/swparrtf.hxx
+++ b/sw/source/filter/rtf/swparrtf.hxx
@@ -303,7 +303,6 @@ class SwRTFParser : public SvxRTFParser
SwFlySaveArr aFlyArr; // Flys als Letzes im Doc setzen
std::vector<bool> aMergeBoxes; // Flags fuer gemergte Zellen
SwListArr aListArr;
- SvPtrarr aTblFmts;
SvPtrarr aRubyCharFmts;
BookmarkPosition* mpBookmarkStart;
sw::util::RedlineStack *mpRedlineStack;