hwpfilter/source/hpara.cxx     |    8 +++----
 hwpfilter/source/hpara.h       |    2 -
 hwpfilter/source/hwpreader.cxx |   44 +++++++++++++++++++++--------------------
 3 files changed, 28 insertions(+), 26 deletions(-)

New commits:
commit b4760a4feefc8696dc29fdd7320b65d2d3b7e523
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Jun 20 11:41:39 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon Jun 20 16:26:58 2022 +0200

    ofz#47118 Timeout
    
    Change-Id: I544074822cfa51ae162afa370c488a1f6132088c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136145
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 9ac169ab4382..52e13b829744 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -166,12 +166,12 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
         auto hBox = readHBox(hwpf);
         if (!hBox)
             return false;
-        hhstr[ii] = std::move(hBox);
-        if (hhstr[ii]->hh == CH_END_PARA)
+        hhstr.emplace_back(std::move(hBox));
+        if (hhstr.back()->hh == CH_END_PARA)
             break;
-        if( hhstr[ii]->hh < CH_END_PARA )
+        if( hhstr.back()->hh < CH_END_PARA )
                 pshape->reserved[0] = 0;
-        ii += hhstr[ii]->WSize();
+        ii += hhstr.back()->WSize();
     }
     return nch && !hwpf.State();
 }
diff --git a/hwpfilter/source/hpara.h b/hwpfilter/source/hpara.h
index 58694899ea38..fcf1681715b7 100644
--- a/hwpfilter/source/hpara.h
+++ b/hwpfilter/source/hpara.h
@@ -114,7 +114,7 @@ class DLLEXPORT HWPPara
 /**
  * Box object list
  */
-        std::map<unsigned short, std::unique_ptr<HBox>> hhstr;
+        std::vector<std::unique_ptr<HBox>> hhstr;
 
         HWPPara(void);
         ~HWPPara(void);
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 05079365b3b3..f5592124b37d 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -2636,11 +2636,8 @@ void HwpReader::make_text_p0(HWPPara * para, bool 
bParaStart)
     startEl("text:span");
     mxList->clear();
 
-    int n = 0;
-    while (n < para->nch)
+    for (const auto& box : para->hhstr)
     {
-        const auto& box = para->hhstr[n];
-
         if (!box->hh)
             break;
 
@@ -2669,7 +2666,6 @@ void HwpReader::make_text_p0(HWPPara * para, bool 
bParaStart)
                 str.push_back(dest[j]);
             }
         }
-        n += box->WSize();
     }
 }
 
@@ -2680,7 +2676,6 @@ void HwpReader::make_text_p0(HWPPara * para, bool 
bParaStart)
 void HwpReader::make_text_p1(HWPPara * para,bool bParaStart)
 {
     hchar_string str;
-    int n;
     int res;
     hchar dest[3];
     int curr = para->cshape->index;
@@ -2712,9 +2707,12 @@ void HwpReader::make_text_p1(HWPPara * para,bool 
bParaStart)
     startEl("text:span");
     mxList->clear();
 
-    for (n = 0; n < para->nch && para->hhstr[n]->hh;
-        n += para->hhstr[n]->WSize())
+    int n = 0;
+    for (const auto& box : para->hhstr)
     {
+        if (!box->hh)
+            break;
+
         if (para->GetCharShape(n)->index != curr)
         {
             makeChars(str);
@@ -2725,13 +2723,13 @@ void HwpReader::make_text_p1(HWPPara * para,bool 
bParaStart)
             startEl("text:span");
             mxList->clear();
         }
-        if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
+        if (box->hh == CH_SPACE && !firstspace)
         {
             makeChars(str);
             startEl("text:s");
             endEl("text:s");
         }
-        else if (para->hhstr[n]->hh == CH_END_PARA)
+        else if (box->hh == CH_END_PARA)
         {
             makeChars(str);
             endEl("text:span");
@@ -2740,18 +2738,19 @@ void HwpReader::make_text_p1(HWPPara * para,bool 
bParaStart)
         }
         else
         {
-            if( para->hhstr[n]->hh < CH_SPACE )
+            if( box->hh < CH_SPACE )
                   continue;
-            if (para->hhstr[n]->hh == CH_SPACE)
+            if (box->hh == CH_SPACE)
                 firstspace = 0;
             else
                 firstspace = 1;
-            res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
+            res = hcharconv(box->hh, dest, UNICODE);
             for( int j = 0 ; j < res; j++ )
             {
                 str.push_back(dest[j]);
             }
         }
+        n += box->WSize();
     }
 }
 
@@ -3581,21 +3580,22 @@ void HwpReader::makeFormula(TxtBox * hbox)
     char mybuf[3000];
     HWPPara* pPar;
 
-    int n, c, res;
     hchar dest[3];
     size_t l = 0;
 
     pPar = hbox->plists[0].empty() ? nullptr : hbox->plists[0].front().get();
     while( pPar )
     {
-        for( n = 0; n < pPar->nch && pPar->hhstr.count(n) && 
pPar->hhstr[n]->hh;
-            n += pPar->hhstr[n]->WSize() )
+        for (const auto& box : pPar->hhstr)
         {
+            if (!box->hh)
+                break;
+
             if (l >= sizeof(mybuf)-7)
                 break;
-            res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
+            int res = hcharconv(box->hh, dest, UNICODE);
             for( int j = 0 ; j < res; j++ ){
-                c = dest[j];
+                int c = dest[j];
                 if( c < 32 )
                     c = ' ';
                 if( c < 256 )
@@ -4460,10 +4460,12 @@ void HwpReader::makeHidden(Hidden * hbox)
 
     while (para)
     {
-        for (int n = 0; n < para->nch && para->hhstr.count(n) && 
para->hhstr[n]->hh;
-            n += para->hhstr[n]->WSize())
+        for (const auto& box : para->hhstr)
         {
-              res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
+              if (!box->hh)
+                  break;
+
+              res = hcharconv(box->hh, dest, UNICODE);
               for( int j = 0 ; j < res ; j++ )
               {
                     str.push_back(dest[j]);

Reply via email to