Kaydet (Commit) e25f37b5 authored tarafından Caolán McNamara's avatar Caolán McNamara Kaydeden (comit) Andras Timar

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 4466a794)

Change-Id: Ie195e0c244cc08643a9c22518c85d70a883752b7
Reviewed-on: https://gerrit.libreoffice.org/17780Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 01339a5b
...@@ -941,8 +941,8 @@ const sal_uInt8* WW8SprmIter::FindSprm(sal_uInt16 nId) ...@@ -941,8 +941,8 @@ const sal_uInt8* WW8SprmIter::FindSprm(sal_uInt16 nId)
WW8PLCFx_PCDAttrs::WW8PLCFx_PCDAttrs(ww::WordVersion eVersion, WW8PLCFx_PCDAttrs::WW8PLCFx_PCDAttrs(ww::WordVersion eVersion,
WW8PLCFx_PCD* pPLCFx_PCD, const WW8ScannerBase* pBase) WW8PLCFx_PCD* pPLCFx_PCD, const WW8ScannerBase* pBase)
: WW8PLCFx(eVersion, true), pPcdI(pPLCFx_PCD->GetPLCFIter()), : WW8PLCFx(eVersion, true), pPcdI(pPLCFx_PCD->GetPLCFIter()),
pPcd(pPLCFx_PCD), pGrpprls(pBase->pPieceGrpprls), pPcd(pPLCFx_PCD), pGrpprls(pBase->aPieceGrpprls.data()),
nGrpprls(pBase->nPieceGrpprls) nGrpprls(pBase->aPieceGrpprls.size())
{ {
} }
...@@ -1527,43 +1527,14 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) ...@@ -1527,43 +1527,14 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF )
return NULL; return NULL;
WW8_FC nClxPos = pWwF->fcClx; WW8_FC nClxPos = pWwF->fcClx;
sal_Int32 nClxLen = pWwF->lcbClx;
sal_Int32 nLeft = nClxLen;
sal_Int16 nGrpprl = 0;
if (!checkSeek(*pStr, nClxPos)) if (!checkSeek(*pStr, nClxPos))
return NULL; return NULL;
while( true ) // Zaehle Zahl der Grpprls sal_Int32 nClxLen = pWwF->lcbClx;
{ sal_Int32 nLeft = nClxLen;
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;
nLeft = nClxLen; while (true)
pPieceGrpprls = new sal_uInt8*[nGrpprl + 1];
memset( pPieceGrpprls, 0, ( nGrpprl + 1 ) * sizeof(sal_uInt8 *) );
nPieceGrpprls = nGrpprl;
sal_Int16 nAktGrpprl = 0; // read Grpprls
while( true )
{ {
sal_uInt8 clxt(2); sal_uInt8 clxt(2);
pStr->ReadUChar( clxt ); pStr->ReadUChar( clxt );
...@@ -1577,6 +1548,8 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) ...@@ -1577,6 +1548,8 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF )
return NULL; // gone wrong return NULL; // gone wrong
if( 1 == clxt ) // clxtGrpprl ? if( 1 == clxt ) // clxtGrpprl ?
{ {
if (aPieceGrpprls.size() == SHRT_MAX)
return NULL;
if (nLen > pStr->remainingSize()) if (nLen > pStr->remainingSize())
return NULL; return NULL;
sal_uInt8* p = new sal_uInt8[nLen+2]; // allocate sal_uInt8* p = new sal_uInt8[nLen+2]; // allocate
...@@ -1586,12 +1559,13 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) ...@@ -1586,12 +1559,13 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF )
delete[] p; delete[] p;
return NULL; return NULL;
} }
pPieceGrpprls[nAktGrpprl++] = p; // trage in Array ein aPieceGrpprls.push_back(p); // add to array
} }
else 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); sal_Int32 nPLCFfLen(0);
if (pWwF->GetFIBVersion() <= ww::eWW2) if (pWwF->GetFIBVersion() <= ww::eWW2)
{ {
...@@ -1607,20 +1581,15 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ) ...@@ -1607,20 +1581,15 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF )
void WW8ScannerBase::DeletePieceTable() void WW8ScannerBase::DeletePieceTable()
{ {
if( pPieceGrpprls ) for (auto pGrppl : aPieceGrpprls)
{ delete[] pGrppl;
for( sal_uInt8** p = pPieceGrpprls; *p; p++ )
delete[] (*p);
delete[] pPieceGrpprls;
pPieceGrpprls = 0;
}
} }
WW8ScannerBase::WW8ScannerBase( SvStream* pSt, SvStream* pTableSt, WW8ScannerBase::WW8ScannerBase( SvStream* pSt, SvStream* pTableSt,
SvStream* pDataSt, WW8Fib* pWwFib ) SvStream* pDataSt, WW8Fib* pWwFib )
: pWw8Fib(pWwFib), pMainFdoa(0), pHdFtFdoa(0), pMainTxbx(0), : pWw8Fib(pWwFib), pMainFdoa(0), pHdFtFdoa(0), pMainTxbx(0),
pMainTxbxBkd(0), pHdFtTxbx(0), pHdFtTxbxBkd(0), pMagicTables(0), pMainTxbxBkd(0), pHdFtTxbx(0), pHdFtTxbxBkd(0), pMagicTables(0),
pSubdocs(0), pExtendedAtrds(0), pPieceGrpprls(0) pSubdocs(0), pExtendedAtrds(0)
{ {
pPiecePLCF = OpenPieceTable( pTableSt, pWw8Fib ); // Complex pPiecePLCF = OpenPieceTable( pTableSt, pWw8Fib ); // Complex
if( pPiecePLCF ) if( pPiecePLCF )
......
...@@ -412,7 +412,7 @@ class WW8PLCFx_PCDAttrs : public WW8PLCFx ...@@ -412,7 +412,7 @@ class WW8PLCFx_PCDAttrs : public WW8PLCFx
private: private:
WW8PLCFpcd_Iter* pPcdI; WW8PLCFpcd_Iter* pPcdI;
WW8PLCFx_PCD* pPcd; 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 SVBT32 aShortSprm; // mini storage: can contain ONE sprm with
// 1 byte param // 1 byte param
sal_uInt16 nGrpprls; // Attribut Anzahl davon sal_uInt16 nGrpprls; // Attribut Anzahl davon
...@@ -1015,8 +1015,7 @@ private: ...@@ -1015,8 +1015,7 @@ private:
WW8PLCFpcd_Iter* pPieceIter; // fuer FastSave ( Iterator dazu ) WW8PLCFpcd_Iter* pPieceIter; // fuer FastSave ( Iterator dazu )
WW8PLCFx_PCD* pPLCFx_PCD; // dito WW8PLCFx_PCD* pPLCFx_PCD; // dito
WW8PLCFx_PCDAttrs* pPLCFx_PCDAttrs; WW8PLCFx_PCDAttrs* pPLCFx_PCDAttrs;
sal_uInt8** pPieceGrpprls; // Attribute an Piece-Table std::vector<sal_uInt8*> aPieceGrpprls; // attributes of Piece-Table
sal_uInt16 nPieceGrpprls; // Anzahl davon
WW8PLCFpcd* OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF ); WW8PLCFpcd* OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF );
void DeletePieceTable(); void DeletePieceTable();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment