[Libreoffice-commits] core.git: hwpfilter/source

Caolán McNamara caolanm at redhat.com
Thu Apr 13 07:53:40 UTC 2017


 hwpfilter/source/hpara.cxx     |   46 +++++++++++++++--------------------------
 hwpfilter/source/hpara.h       |    6 ++---
 hwpfilter/source/hwpfile.cxx   |   13 +++++------
 hwpfilter/source/hwpfile.h     |    4 +--
 hwpfilter/source/hwpreader.cxx |    6 ++---
 5 files changed, 31 insertions(+), 44 deletions(-)

New commits:
commit 3b9b4ca5d3aa15d51d6b54a5f5f23967f1666889
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sat Apr 8 21:04:45 2017 +0100

    ofz#1062 ensure cshape lifecycle matches expectations
    
    Change-Id: I586e9b3546516a0f05d86b2f7dd93e7c292a6795
    Reviewed-on: https://gerrit.libreoffice.org/36298
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 84294c59ed3c..0273bcca29c3 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -75,17 +75,14 @@ HWPPara::HWPPara()
     , etcflag(0)
     , ctrlflag(0)
     , pstyno(0)
-    , linfo(nullptr)
-    , cshapep(nullptr)
+    , cshape(new CharShape)
 {
-    memset(&cshape, 0, sizeof(cshape));
+    memset(cshape.get(), 0, sizeof(cshape));
     memset(&pshape, 0, sizeof(pshape));
 }
 
 HWPPara::~HWPPara()
 {
-    delete[] linfo;
-    delete[] cshapep;
 }
 
 bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
@@ -102,36 +99,33 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
     hwpf.Read4b(&ctrlflag, 1);
     hwpf.Read1b(&pstyno, 1);
 
-
 /* Paragraph representative character */
-    cshape.Read(hwpf);
+    cshape->Read(hwpf);
     if (nch > 0)
-        hwpf.AddCharShape(&cshape);
+        hwpf.AddCharShape(cshape);
 
 /* Paragraph paragraphs shape  */
     if (nch && !reuse_shape)
     {
         pshape.Read(hwpf);
-        pshape.cshape = &cshape;
-          pshape.pagebreak = etcflag;
+        pshape.cshape = cshape.get();
+        pshape.pagebreak = etcflag;
     }
 
-    linfo = ::comphelper::newArray_null<LineInfo>(nline);
-    if (!linfo) { return false; }
+    linfo.reset(::comphelper::newArray_null<LineInfo>(nline));
     for (ii = 0; ii < nline; ii++)
     {
         linfo[ii].Read(hwpf, this);
     }
-     if( etcflag & 0x04 ){
+    if( etcflag & 0x04 ){
          hwpf.AddColumnInfo();
-     }
+    }
 
     if (nch && !reuse_shape){
          if( pshape.coldef.ncols > 1 ){
              hwpf.SetColumnDef( &pshape.coldef );
          }
-     }
-
+    }
 
     if( nline > 0 )
     {
@@ -144,23 +138,19 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
 
     if (contain_cshape)
     {
-        cshapep = ::comphelper::newArray_null<CharShape>(nch);
-        if (!cshapep)
-        {
-            perror("Memory Allocation: cshape\n");
-            return false;
-        }
-        memset(cshapep, 0, nch * sizeof(CharShape));
+        cshapep.resize(nch);
 
         for (ii = 0; ii < nch; ii++)
         {
+            cshapep[ii].reset(new CharShape);
+            memset(cshapep[ii].get(), 0, sizeof(CharShape));
 
             hwpf.Read1b(&same_cshape, 1);
             if (!same_cshape)
             {
-                cshapep[ii].Read(hwpf);
+                cshapep[ii]->Read(hwpf);
                 if (nch > 1)
-                    hwpf.AddCharShape(&cshapep[ii]);
+                    hwpf.AddCharShape(cshapep[ii]);
             }
             else if (ii == 0)
                 cshapep[ii] = cshape;
@@ -185,15 +175,13 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
     return nch && !hwpf.State();
 }
 
-
 CharShape *HWPPara::GetCharShape(int pos)
 {
     if (contain_cshape == 0)
-        return &cshape;
-    return cshapep + pos;
+        return cshape.get();
+    return cshapep[pos].get();
 }
 
-
 std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
 {
     std::unique_ptr<HBox> hbox;
diff --git a/hwpfilter/source/hpara.h b/hwpfilter/source/hpara.h
index 6496eae80f70..1385f12ed698 100644
--- a/hwpfilter/source/hpara.h
+++ b/hwpfilter/source/hpara.h
@@ -103,11 +103,11 @@ class DLLEXPORT HWPPara
  */
         unsigned long     ctrlflag;
         unsigned char     pstyno;
-        CharShape     cshape;                     /* When characters are all the same shape */
+        std::shared_ptr<CharShape> cshape;                     /* When characters are all the same shape */
         ParaShape     pshape;                     /* if reuse flag is 0, */
 
-        LineInfo      *linfo;
-        CharShape     *cshapep;
+        std::unique_ptr<LineInfo[]> linfo;
+        std::vector<std::shared_ptr<CharShape>>   cshapep;
 /**
  * Box object list
  */
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 3ab2b0087a6c..f883a2243f40 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -245,8 +245,8 @@ void HWPFile::ParaListRead()
 bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag)
 {
     std::unique_ptr<HWPPara> spNode( new HWPPara );
-     unsigned char tmp_etcflag;
-     unsigned char prev_etcflag = 0;
+    unsigned char tmp_etcflag;
+    unsigned char prev_etcflag = 0;
     while (spNode->Read(*this, flag))
     {
          if( !(spNode->etcflag & 0x04) ){
@@ -492,7 +492,7 @@ CharShape *HWPFile::getCharShape(int index)
 {
     if (index < 0 || static_cast<unsigned int>(index) >= cslist.size())
         return nullptr;
-    return cslist[index];
+    return cslist[index].get();
 }
 
 FBoxStyle *HWPFile::getFBoxStyle(int index)
@@ -562,11 +562,10 @@ void HWPFile::AddParaShape(ParaShape * pshape)
         pshape->index = value;
 }
 
-
-void HWPFile::AddCharShape(CharShape * cshape)
+void HWPFile::AddCharShape(std::shared_ptr<CharShape>& cshape)
 {
-    int value = compareCharShape(cshape);
-    if( value == 0 )
+    int value = compareCharShape(cshape.get());
+    if (value == 0)
     {
         cshape->index = ++ccount;
         cslist.push_back(cshape);
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 1d8da3673169..7f3d29f80225 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -213,7 +213,7 @@ class DLLEXPORT HWPFile
         void AddColumnInfo();
         void SetColumnDef(ColumnDef *coldef);
         void AddParaShape(ParaShape *);
-        void AddCharShape(CharShape *);
+        void AddCharShape(std::shared_ptr<CharShape>&);
         void AddFBoxStyle(FBoxStyle *);
         void AddDateFormat(DateCode *);
         void AddHeaderFooter(HeaderFooter *);
@@ -284,7 +284,7 @@ class DLLEXPORT HWPFile
         std::list<HyperText*> hyperlist;
         int currenthyper;
         std::vector<ParaShape*> pslist;             /* 스타오피스의 구조상 필요 */
-        std::vector<CharShape*> cslist;
+        std::vector<std::shared_ptr<CharShape>> cslist;
         std::vector<FBoxStyle*> fbslist;
         std::vector<DateCode*> datecodes;
         std::vector<HeaderFooter*> headerfooters;
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 9d5a331be14b..fa93b38b1d63 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -2742,7 +2742,7 @@ void HwpReader::make_text_p0(HWPPara * para, bool bParaStart)
         d->bInHeader = false;
     }
     padd("text:style-name", sXML_CDATA,
-        ascii(getTStyleName(para->cshape.index, buf)));
+        ascii(getTStyleName(para->cshape->index, buf)));
     rstartEl("text:span", mxList.get());
     mxList->clear();
 
@@ -2786,8 +2786,8 @@ void HwpReader::make_text_p1(HWPPara * para,bool bParaStart)
     hchar_string str;
     int n;
     int res;
-     hchar dest[3];
-    int curr = para->cshape.index;
+    hchar dest[3];
+    int curr = para->cshape->index;
     unsigned char firstspace = 0;
 
     if( !bParaStart )


More information about the Libreoffice-commits mailing list