diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-04-08 21:04:45 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-04-12 15:54:22 +0200 |
commit | 4e175b7aee7c00c6d0d8449a19b26ebf25446b9d (patch) | |
tree | bea6bccdc858cd77aa6d9b5ee2d29d1cfcc45cb5 /hwpfilter/source | |
parent | 3e4e13300db6a0c2c60dbe733d96ff5a7b0d32e5 (diff) |
ofz#1062 ensure cshape lifecycle matches expectations
Change-Id: I586e9b3546516a0f05d86b2f7dd93e7c292a6795
Reviewed-on: https://gerrit.libreoffice.org/36300
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'hwpfilter/source')
-rw-r--r-- | hwpfilter/source/hpara.cxx | 34 | ||||
-rw-r--r-- | hwpfilter/source/hpara.h | 4 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.cxx | 13 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.h | 4 | ||||
-rw-r--r-- | hwpfilter/source/hwpreader.cxx | 6 |
5 files changed, 26 insertions, 35 deletions
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx index 84294c59ed3c..3149d65acf0a 100644 --- a/hwpfilter/source/hpara.cxx +++ b/hwpfilter/source/hpara.cxx @@ -75,17 +75,16 @@ HWPPara::HWPPara() , etcflag(0) , ctrlflag(0) , pstyno(0) + , cshape(new CharShape) , linfo(nullptr) - , cshapep(nullptr) { - 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,18 +101,17 @@ 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); @@ -144,23 +142,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 +179,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..b598c201b569 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::vector<std::shared_ptr<CharShape>> cshapep; /** * Box object list */ diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index f0a9f4279c4f..929a783d0761 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -242,8 +242,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) ){ @@ -467,7 +467,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) @@ -537,11 +537,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 c3d8766c4297..27c3b514417e 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -2737,7 +2737,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(); @@ -2781,8 +2781,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 ) |