[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - sw/source

Caolán McNamara caolanm at redhat.com
Mon Aug 17 01:25:21 PDT 2015


 sw/source/filter/ww8/ww8scan.cxx |   59 +++++++++------------------------------
 sw/source/filter/ww8/ww8scan.hxx |    5 +--
 2 files changed, 16 insertions(+), 48 deletions(-)

New commits:
commit b9b21621cfdc742b7bb54e77e55c318d1a7b6bc5
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Aug 14 15:45:18 2015 +0100

    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/17783
    Reviewed-by: David Tardon <dtardon at redhat.com>
    Tested-by: David Tardon <dtardon at redhat.com>

diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index f243e4b..b77936e 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -939,8 +939,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())
 {
 }
 
@@ -1525,43 +1525,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 );
@@ -1575,6 +1546,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
@@ -1584,12 +1557,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)
     {
@@ -1605,20 +1579,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* pTblSt,
     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( pTblSt, pWw8Fib );             // Complex
     if( pPiecePLCF )
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 747fdff..e054b9d 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -415,7 +415,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
@@ -1027,8 +1027,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();


More information about the Libreoffice-commits mailing list