Kaydet (Commit) 4466a794 authored tarafından Caolán McNamara's avatar Caolán McNamara

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

Change-Id: Ie195e0c244cc08643a9c22518c85d70a883752b7
üst 6d78caf6
......@@ -936,8 +936,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())
{
}
......@@ -1504,43 +1504,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 ) // count number of Grpprls
{
sal_uInt8 clxt(2);
pStr->ReadUChar( clxt );
nLeft--;
if( 2 == clxt ) // PLCFfpcd ?
break; // PLCFfpcd found
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 ); // ignore 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 );
......@@ -1554,6 +1525,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
......@@ -1563,11 +1536,12 @@ WW8PLCFpcd* WW8ScannerBase::OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF )
delete[] p;
return NULL;
}
pPieceGrpprls[nAktGrpprl++] = p; // add to array
aPieceGrpprls.push_back(p); // add to array
}
else
pStr->SeekRel( nLen ); // non-Grpprl left
pStr->SeekRel( nLen ); // non-Grpprl left
}
// read Piece Table PLCF
sal_Int32 nPLCFfLen(0);
if (pWwF->GetFIBVersion() <= ww::eWW2)
......@@ -1584,20 +1558,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 )
......
......@@ -412,7 +412,7 @@ class WW8PLCFx_PCDAttrs : public WW8PLCFx
private:
WW8PLCFpcd_Iter* pPcdI;
WW8PLCFx_PCD* pPcd;
sal_uInt8** const pGrpprls; // attribute of 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; // attribute count of this
......@@ -1011,8 +1011,7 @@ private:
WW8PLCFpcd_Iter* pPieceIter; // for FastSave ( iterator for previous )
WW8PLCFx_PCD* pPLCFx_PCD; // ditto
WW8PLCFx_PCDAttrs* pPLCFx_PCDAttrs;
sal_uInt8** pPieceGrpprls; // attributes of Piece-Table
sal_uInt16 nPieceGrpprls; // number of such attributes
std::vector<sal_uInt8*> aPieceGrpprls; // attributes of Piece-Table
WW8PLCFpcd* OpenPieceTable( SvStream* pStr, const WW8Fib* pWwF );
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