hwpfilter/source/hbox.cxx | 12 +--- hwpfilter/source/hbox.h | 7 +- hwpfilter/source/hwpread.cxx | 128 +++++++++++++++++++++---------------------- 3 files changed, 71 insertions(+), 76 deletions(-)
New commits: commit 032e7a4b5c4904d00b3f0ab75af113ed316343f8 Author: Caolán McNamara <[email protected]> Date: Fri Apr 28 12:52:01 2017 +0100 ofz: avoid timeout and return early on failure Change-Id: I083aa07b311fa073ea5eeb1d569b0902e0f9c095 diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h index 5ed353364c0f..a110d70d0f32 100644 --- a/hwpfilter/source/hbox.h +++ b/hwpfilter/source/hbox.h @@ -228,7 +228,7 @@ struct Cell // Cell unsigned char diagonal; // { 0=none,\=1,/=2,X=3} unsigned char protect; - void Read( HWPFile &hwpf ); + bool Read(HWPFile &hwpf); }; /** diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index 1a96eaa29046..92f484b1d10d 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -185,7 +185,7 @@ static void UpdateBBox(FBox * fbox) fbox->boundey = fbox->pgy + fbox->ys - 1; } -void Cell::Read(HWPFile & hwpf) +bool Cell::Read(HWPFile & hwpf) { hwpf.Read2b(&p, 1); hwpf.Read2b(&color, 1); @@ -203,7 +203,7 @@ void Cell::Read(HWPFile & hwpf) hwpf.Read1b(linetype, 4); hwpf.Read1b(&shade, 1); hwpf.Read1b(&diagonal, 1); - hwpf.Read1b(&protect, 1); + return hwpf.Read1b(&protect, 1) == 1; } bool TxtBox::Read(HWPFile & hwpf) @@ -288,11 +288,14 @@ bool TxtBox::Read(HWPFile & hwpf) if (!cell) { return hwpf.SetState(HWP_InvalidFileFormat); } - for (ii = 0; ii < ncell; ii++) + bool bSuccess = true; + for (ii = 0; ii < ncell && bSuccess; ii++) { - cell[ii].Read(hwpf); + bSuccess = cell[ii].Read(hwpf); cell[ii].key = sal::static_int_cast<unsigned char>(ii); } + if (!bSuccess) + return false; if (ncell == 1) style.cell = &cell[0]; plists.resize(ncell); commit 6394fd4a1d56af4afab4f9683d5a2087a32588e6 Author: Caolán McNamara <[email protected]> Date: Fri Apr 28 12:49:19 2017 +0100 convert to std::vector Change-Id: I315755d49df5d29c6c7075237b7401f16c89b449 diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx index 88e76c7ca7f8..479279f2bc49 100644 --- a/hwpfilter/source/hbox.cxx +++ b/hwpfilter/source/hbox.cxx @@ -356,19 +356,18 @@ TxtBox::TxtBox() , protect(0) , cell(nullptr) , m_pTable(nullptr) - , plists(nullptr) { reserved[0] = reserved[1] = 0; } TxtBox::~TxtBox() { - delete[]cell; + delete[] cell; - for (int ii = 0; ii < nCell; ++ii) + for (auto& entry : plists) { - std::list < HWPPara* >::iterator it = plists[ii].begin(); - for (; it != plists[ii].end(); ++it) + std::list < HWPPara* >::iterator it = entry.begin(); + for (; it != entry.end(); ++it) { HWPPara* pPara = *it; delete pPara; @@ -381,11 +380,8 @@ TxtBox::~TxtBox() HWPPara* pPara = *it; delete pPara; } - - delete[]plists; } - // picture(11) Picture::Picture() diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h index 15c97c6363f4..5ed353364c0f 100644 --- a/hwpfilter/source/hbox.h +++ b/hwpfilter/source/hbox.h @@ -360,11 +360,12 @@ struct TxtBox: public FBox short protect; //1=size lock Cell *cell; - Table *m_pTable; + Table *m_pTable; /** * Paragraph list */ - std::list<HWPPara*> *plists; + std::vector<std::list<HWPPara*>> plists; + /** * Caption */ diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index ca2a90905e50..1a96eaa29046 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -295,10 +295,7 @@ bool TxtBox::Read(HWPFile & hwpf) } if (ncell == 1) style.cell = &cell[0]; - plists = ::comphelper::newArray_null< std::list< HWPPara* > >(ncell); - if (!plists) { - return hwpf.SetState(HWP_InvalidFileFormat); - } + plists.resize(ncell); for (ii = 0; ii < ncell; ii++) hwpf.ReadParaList(plists[ii]); // caption commit f30fb61c650e8b844501dcbbccbd441528b75997 Author: Caolán McNamara <[email protected]> Date: Fri Apr 28 12:36:10 2017 +0100 fix indent Change-Id: I75faea4d701f401c5367142e4710ae613c8834be diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index eb27376cdc77..ca2a90905e50 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -206,7 +206,6 @@ void Cell::Read(HWPFile & hwpf) hwpf.Read1b(&protect, 1); } - bool TxtBox::Read(HWPFile & hwpf) { int ii, ncell; @@ -292,7 +291,7 @@ bool TxtBox::Read(HWPFile & hwpf) for (ii = 0; ii < ncell; ii++) { cell[ii].Read(hwpf); - cell[ii].key = sal::static_int_cast<unsigned char>(ii); + cell[ii].key = sal::static_int_cast<unsigned char>(ii); } if (ncell == 1) style.cell = &cell[0]; @@ -305,65 +304,64 @@ bool TxtBox::Read(HWPFile & hwpf) // caption hwpf.ReadParaList(caption); - if( type == 0 ){ // if table? - TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell); - if (!pArr) { - return hwpf.SetState(HWP_InvalidFileFormat); - } - Table *tbl = new Table; - for( ii = 0 ; ii < ncell; ii++) - { - tbl->columns.insert(cell[ii].x); - tbl->columns.insert(cell[ii].x + cell[ii].w); - tbl->rows.insert(cell[ii].y); - tbl->rows.insert(cell[ii].y + cell[ii].h); - } - for( ii = 0 ; ii < ncell; ii++) - { - TCell *tcell = new TCell; - tcell->nColumnIndex = tbl->columns.getIndex(cell[ii].x); - tcell->nColumnSpan = tbl->columns.getIndex(cell[ii].x + cell[ii].w) - - tcell->nColumnIndex; - tcell->nRowIndex = tbl->rows.getIndex(cell[ii].y); - tcell->nRowSpan = tbl->rows.getIndex(cell[ii].y + cell[ii].h) - - tcell->nRowIndex; - tcell->pCell = &cell[ii]; - pArr[ii] = tcell; - } - TCell *tmp; - // Sort by row and column - for( ii = 0 ; ii < ncell - 1; ii++ ){ - for( int jj = ii ; jj < ncell ; jj++){ - if( pArr[ii]->nRowIndex > pArr[jj]->nRowIndex ){ - tmp = pArr[ii]; - pArr[ii] = pArr[jj]; - pArr[jj] = tmp; - } - } - for( int kk = ii ; kk > 0 ; kk--){ - if( ( pArr[kk]->nRowIndex == pArr[kk-1]->nRowIndex ) && - (pArr[kk]->nColumnIndex < pArr[kk-1]->nColumnIndex )){ - tmp = pArr[kk]; - pArr[kk] = pArr[kk-1]; - pArr[kk-1] = tmp; - } - } - } - for( ii = 0 ; ii < ncell ; ii++ ){ - tbl->cells.push_back(pArr[ii]); - } - tbl->box = this; - hwpf.AddTable(tbl); - m_pTable = tbl; - delete[] pArr; - } - else - m_pTable = nullptr; + if( type == 0 ){ // if table? + TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell); + if (!pArr) { + return hwpf.SetState(HWP_InvalidFileFormat); + } + Table *tbl = new Table; + for( ii = 0 ; ii < ncell; ii++) + { + tbl->columns.insert(cell[ii].x); + tbl->columns.insert(cell[ii].x + cell[ii].w); + tbl->rows.insert(cell[ii].y); + tbl->rows.insert(cell[ii].y + cell[ii].h); + } + for( ii = 0 ; ii < ncell; ii++) + { + TCell *tcell = new TCell; + tcell->nColumnIndex = tbl->columns.getIndex(cell[ii].x); + tcell->nColumnSpan = tbl->columns.getIndex(cell[ii].x + cell[ii].w) - + tcell->nColumnIndex; + tcell->nRowIndex = tbl->rows.getIndex(cell[ii].y); + tcell->nRowSpan = tbl->rows.getIndex(cell[ii].y + cell[ii].h) - + tcell->nRowIndex; + tcell->pCell = &cell[ii]; + pArr[ii] = tcell; + } + TCell *tmp; + // Sort by row and column + for( ii = 0 ; ii < ncell - 1; ii++ ){ + for( int jj = ii ; jj < ncell ; jj++){ + if( pArr[ii]->nRowIndex > pArr[jj]->nRowIndex ){ + tmp = pArr[ii]; + pArr[ii] = pArr[jj]; + pArr[jj] = tmp; + } + } + for( int kk = ii ; kk > 0 ; kk--){ + if( ( pArr[kk]->nRowIndex == pArr[kk-1]->nRowIndex ) && + (pArr[kk]->nColumnIndex < pArr[kk-1]->nColumnIndex )){ + tmp = pArr[kk]; + pArr[kk] = pArr[kk-1]; + pArr[kk-1] = tmp; + } + } + } + for( ii = 0 ; ii < ncell ; ii++ ){ + tbl->cells.push_back(pArr[ii]); + } + tbl->box = this; + hwpf.AddTable(tbl); + m_pTable = tbl; + delete[] pArr; + } + else + m_pTable = nullptr; return !hwpf.State(); } - // picture(11) bool Picture::Read(HWPFile & hwpf) {
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
