diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-08-14 15:45:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-08-17 07:48:41 +0000 |
commit | 3a03e386e04fda88c0b964ecdb8dc11e4f532b86 (patch) | |
tree | ae35792dc5ac3786fe5c6157a49f054ea6f904cb /sw | |
parent | d510b85aa5e1c51f5bf4e08edf47725a7a75ce04 (diff) |
convert pPieceGrpprls to vector and merge calc and load loops together
we retain the max-short limit but no longer add a null terminating entry
(cherry picked from commit 4466a7949af63621a2b180715de2ae3675343715)
Change-Id: Ie195e0c244cc08643a9c22518c85d70a883752b7
Reviewed-on: https://gerrit.libreoffice.org/17780
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/filter/ww8/ww8scan.cxx | 59 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8scan.hxx | 5 |
2 files changed, 16 insertions, 48 deletions
diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index e9243ba1ff04..5ffe258b14ba 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -941,8 +941,8 @@ const sal_uInt8* WW8SprmIter::FindSprm(sal_uInt16 nId) WW8PLCFx_PCDAttrs::WW8PLCFx_PCDAttrs(ww::WordVersion eVersion, WW8PLCFx_PCD* pPLCFx_PCD, const WW8ScannerBase* pBase) : WW8PLCFx(eVersion, true), pPcdI(pPLCFx_PCD->GetPLCFIter()), - pPcd(pPLCFx_PCD), pGrpprls(pBase->pPieceGrpprls), - nGrpprls(pBase->nPieceGrpprls) + pPcd(pPLCFx_PCD), pGrpprls(pBase->aPieceGrpprls.data()), + nGrpprls(pBase->aPieceGrpprls.size()) { } @@ -1527,43 +1527,14 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) return NULL; WW8_FC nClxPos = pWwF->fcClx; - sal_Int32 nClxLen = pWwF->lcbClx; - sal_Int32 nLeft = nClxLen; - sal_Int16 nGrpprl = 0; if (!checkSeek(*pStr, nClxPos)) return NULL; - while( true ) // Zaehle Zahl der Grpprls - { - sal_uInt8 clxt(2); - pStr->ReadUChar( clxt ); - nLeft--; - if( 2 == clxt ) // PLCFfpcd ? - break; // PLCFfpcd gefunden - if( 1 == clxt ) // clxtGrpprl ? - { - if (nGrpprl == SHRT_MAX) - return NULL; - nGrpprl++; - } - sal_uInt16 nLen(0); - pStr->ReadUInt16( nLen ); - nLeft -= 2 + nLen; - if( nLeft < 0 ) - return NULL; // gone wrong - pStr->SeekRel( nLen ); // ueberlies grpprl - } - - if (!checkSeek(*pStr, nClxPos)) - return NULL; + sal_Int32 nClxLen = pWwF->lcbClx; + sal_Int32 nLeft = nClxLen; - nLeft = nClxLen; - pPieceGrpprls = new sal_uInt8*[nGrpprl + 1]; - memset( pPieceGrpprls, 0, ( nGrpprl + 1 ) * sizeof(sal_uInt8 *) ); - nPieceGrpprls = nGrpprl; - sal_Int16 nAktGrpprl = 0; // read Grpprls - while( true ) + while (true) { sal_uInt8 clxt(2); pStr->ReadUChar( clxt ); @@ -1577,6 +1548,8 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) return NULL; // gone wrong if( 1 == clxt ) // clxtGrpprl ? { + if (aPieceGrpprls.size() == SHRT_MAX) + return NULL; if (nLen > pStr->remainingSize()) return NULL; sal_uInt8* p = new sal_uInt8[nLen+2]; // allocate @@ -1586,12 +1559,13 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) delete[] p; return NULL; } - pPieceGrpprls[nAktGrpprl++] = p; // trage in Array ein + aPieceGrpprls.push_back(p); // add to array } else - pStr->SeekRel( nLen ); // ueberlies nicht-Grpprl + pStr->SeekRel( nLen ); // non-Grpprl left } - // lies Piece Table PLCF ein + + // read Piece Table PLCF sal_Int32 nPLCFfLen(0); if (pWwF->GetFIBVersion() <= ww::eWW2) { @@ -1607,20 +1581,15 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) void WW8ScannerBase::DeletePieceTable() { - if( pPieceGrpprls ) - { - for( sal_uInt8** p = pPieceGrpprls; *p; p++ ) - delete[] (*p); - delete[] pPieceGrpprls; - pPieceGrpprls = 0; - } + for (auto pGrppl : aPieceGrpprls) + delete[] pGrppl; } WW8ScannerBase::WW8ScannerBase( SvStream* pSt, SvStream* pTableSt, SvStream* pDataSt, WW8Fib* pWwFib ) : pWw8Fib(pWwFib), pMainFdoa(0), pHdFtFdoa(0), pMainTxbx(0), pMainTxbxBkd(0), pHdFtTxbx(0), pHdFtTxbxBkd(0), pMagicTables(0), - pSubdocs(0), pExtendedAtrds(0), pPieceGrpprls(0) + pSubdocs(0), pExtendedAtrds(0) { pPiecePLCF = OpenPieceTable( pTableSt, pWw8Fib ); // Complex if( pPiecePLCF ) diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx index 57ccae3aca50..0d6ac9434871 100644 --- a/sw/source/filter/ww8/ww8scan.hxx +++ b/sw/source/filter/ww8/ww8scan.hxx @@ -412,7 +412,7 @@ class WW8PLCFx_PCDAttrs : public WW8PLCFx private: WW8PLCFpcd_Iter* pPcdI; WW8PLCFx_PCD* pPcd; - sal_uInt8** const pGrpprls; // Attribute an Piece-Table + sal_uInt8* const* pGrpprls; // attribute of Piece-table SVBT32 aShortSprm; // mini storage: can contain ONE sprm with // 1 byte param sal_uInt16 nGrpprls; // Attribut Anzahl davon @@ -1015,8 +1015,7 @@ private: WW8PLCFpcd_Iter* pPieceIter; // fuer FastSave ( Iterator dazu ) WW8PLCFx_PCD* pPLCFx_PCD; // dito WW8PLCFx_PCDAttrs* pPLCFx_PCDAttrs; - sal_uInt8** pPieceGrpprls; // Attribute an Piece-Table - sal_uInt16 nPieceGrpprls; // Anzahl davon + std::vector<sal_uInt8*> aPieceGrpprls; // attributes of Piece-Table WW8PLCFpcd* OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ); void DeletePieceTable(); |