[Libreoffice-commits] .: 3 commits - comphelper/inc comphelper/Package_inc.mk hwpfilter/Library_hwp.mk hwpfilter/source sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Jul 24 02:37:43 PDT 2012


 comphelper/Package_inc.mk              |    1 
 comphelper/inc/comphelper/newarray.hxx |   51 +++++
 hwpfilter/Library_hwp.mk               |    1 
 hwpfilter/source/drawdef.h             |    2 
 hwpfilter/source/drawing.h             |    7 
 hwpfilter/source/formula.cxx           |   25 +-
 hwpfilter/source/hbox.cxx              |   56 ++---
 hwpfilter/source/hbox.h                |   50 ++---
 hwpfilter/source/hcode.cxx             |  196 ++++++++------------
 hwpfilter/source/hcode.h               |   10 -
 hwpfilter/source/himgutil.cxx          |  163 ----------------
 hwpfilter/source/himgutil.h            |   60 ------
 hwpfilter/source/hpara.cxx             |   10 -
 hwpfilter/source/hstyle.cxx            |    4 
 hwpfilter/source/htags.cxx             |    6 
 hwpfilter/source/hwplib.h              |    5 
 hwpfilter/source/hwpread.cxx           |   41 +++-
 hwpfilter/source/hwpreader.cxx         |  323 +++++++++++++++------------------
 hwpfilter/source/hwpreader.hxx         |    4 
 hwpfilter/source/mapping.h             |   28 +-
 sw/source/filter/rtf/swparrtf.cxx      |   16 +
 21 files changed, 435 insertions(+), 624 deletions(-)

New commits:
commit 5a243f140975167aa5c42c95b30edb1cdb1ea639
Author: Michael Stahl <mst at openoffice.org>
Date:   Tue Jul 24 11:36:17 2012 +0200

    hwpfilter: improve text import and error handling
    
    Change-Id: Ib74b96200c9d57f55fc0d32b638601c64e7eb6fe

diff --git a/hwpfilter/Library_hwp.mk b/hwpfilter/Library_hwp.mk
index bc51391..1fa67d2 100644
--- a/hwpfilter/Library_hwp.mk
+++ b/hwpfilter/Library_hwp.mk
@@ -64,7 +64,6 @@ $(eval $(call gb_Library_add_exception_objects,hwp,\
     hwpfilter/source/hcode \
     hwpfilter/source/hfont \
     hwpfilter/source/hgzip \
-    hwpfilter/source/himgutil \
     hwpfilter/source/hinfo \
     hwpfilter/source/hiodev \
     hwpfilter/source/hpara \
diff --git a/hwpfilter/source/drawdef.h b/hwpfilter/source/drawdef.h
index 685b51e..c5861e7 100644
--- a/hwpfilter/source/drawdef.h
+++ b/hwpfilter/source/drawdef.h
@@ -165,7 +165,7 @@ struct HWPDOProperty
 
     ZZPoint offset1;
     ZZPoint offset2;
-    char szPatternFile[MAX_PATH + 1];
+    char szPatternFile[260 + 1];
     char pictype;
 };
 
diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h
index 4be35a0..00d9225 100644
--- a/hwpfilter/source/drawing.h
+++ b/hwpfilter/source/drawing.h
@@ -27,6 +27,8 @@
 
 #include <osl/diagnose.h>
 
+#include <comphelper/newarray.hxx>
+
 #include "hwplib.h"
 #include "hwpfile.h"
 #include "hiodev.h"
@@ -347,6 +349,7 @@ static HWPDrawingObject *LoadDrawingObject(void)
             hdo->child = LoadDrawingObject();
             if (hdo->child == NULL)
             {
+                goto error;
             }
         }
         if (prev == NULL)
@@ -543,7 +546,8 @@ int cmd, void *argp, int argv)
                 return OBJRET_FILE_ERROR;
             if (hdo->u.freeform.npt)
             {
-                hdo->u.freeform.pt = new ZZPoint[hdo->u.freeform.npt];
+                hdo->u.freeform.pt =
+                    ::comphelper::newArray_null<ZZPoint>(hdo->u.freeform.npt);
                 if (hdo->u.freeform.pt == NULL)
                 {
                     hdo->u.freeform.npt = 0;
@@ -630,6 +634,7 @@ int cmd, void *argp, int argv)
 }
 
 
+
 static int
 HWPDOContainerFunc(int type, HWPDrawingObject * hdo,
 int cmd, void *argp, int argv)
diff --git a/hwpfilter/source/formula.cxx b/hwpfilter/source/formula.cxx
index 0e6b36d..03e6be2 100644
--- a/hwpfilter/source/formula.cxx
+++ b/hwpfilter/source/formula.cxx
@@ -32,7 +32,6 @@ extern std::list<Node*> nodelist;
 
 #include "hcode.h"
 
-static hchar entity[32];
 #define ascii(x)  OUString::createFromAscii(x)
 #define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(0)
 #define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(0)
@@ -41,7 +40,6 @@ static hchar entity[32];
 #define reucstr(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(OUString(x,y, RTL_TEXTENCODING_EUC_KR)); } while(0)
 #define padd(x,y,z)  pList->addAttribute(x,y,z)
 #else
-static char entity[32];
 static int indent = 0;
 #define inds indent++; for(int i = 0 ; i < indent ; i++) fprintf(stderr," ")
 #define inde for(int i = 0 ; i < indent ; i++) fprintf(stderr," "); indent--
@@ -222,11 +220,12 @@ void Formula::makeIdentifier(Node *res)
      case ID_IDENTIFIER :
 #ifdef DEBUG
           inds;
-          fprintf(stderr,"<math:mi>%s</math:mi>\n",getMathMLEntity(tmp->value, entity));
+          fprintf(stderr,"<math:mi>%s</math:mi>\n",
+                  getMathMLEntity(tmp->value).c_str());
           indo;
 #else
           rstartEl(ascii("math:mi"), rList);
-          runistr(getMathMLEntity(tmp->value, entity));
+          runistr(getMathMLEntity(tmp->value).c_str());
           rendEl(ascii("math:mi"));
 #endif
           break;
@@ -248,7 +247,7 @@ void Formula::makeIdentifier(Node *res)
           inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo;
 #else
           rstartEl(ascii("math:mo"), rList);
-          runistr(getMathMLEntity(tmp->value,entity));
+          runistr(getMathMLEntity(tmp->value).c_str());
           rendEl(ascii("math:mo"));
 #endif
           break;
@@ -404,11 +403,12 @@ void Formula::makeDecoration(Node *res)
 
 #ifdef DEBUG
      inds;
-     fprintf(stderr,"<math:mo>%s</math:mo>\n", getMathMLEntity(tmp->value,entity));
+     fprintf(stderr,"<math:mo>%s</math:mo>\n",
+             getMathMLEntity(tmp->value).c_str());
      indo;
 #else
      rstartEl(ascii("math:mo"), rList);
-     runistr(getMathMLEntity(tmp->value,entity));
+     runistr(getMathMLEntity(tmp->value).c_str());
      rendEl(ascii("math:mo"));
 #endif
 
@@ -529,11 +529,14 @@ void Formula::makeFence(Node *res)
      Node *tmp = res->child;
 #ifdef DEBUG
      inds;
-     fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n",getMathMLEntity(tmp->value, entity),
-                getMathMLEntity(tmp->next->next->value,entity));
+     fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n",
+                getMathMLEntity(tmp->value).c_str(),
+                getMathMLEntity(tmp->next->next->value).c_str());
 #else
-     padd(ascii("open"), ascii("CDATA"), OUString(getMathMLEntity(tmp->value,entity)) );
-     padd(ascii("close"), ascii("CDATA"), OUString(getMathMLEntity(tmp->next->next->value,entity)) );
+     padd(ascii("open"), ascii("CDATA"),
+             OUString(getMathMLEntity(tmp->value).c_str()) );
+     padd(ascii("close"), ascii("CDATA"),
+             OUString(getMathMLEntity(tmp->next->next->value).c_str()) );
      rstartEl(ascii("math:mfenced"), rList);
      pList->clear();
 #endif
diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx
index b1e92e9..033df90 100644
--- a/hwpfilter/source/hbox.cxx
+++ b/hwpfilter/source/hbox.cxx
@@ -63,11 +63,11 @@ int HBox::WSize(void)
 }
 
 
-int HBox::GetString(hchar * hstr, int )
+hchar_string HBox::GetString()
 {
-    *hstr++ = hh;
-    *hstr = 0;
-    return 1;
+    hchar_string ret;
+    ret.push_back(hh);
+    return ret;
 }
 
 
@@ -143,10 +143,10 @@ DateCode::DateCode(void):HBox(CH_DATE_CODE)
 #define _DATECODE_WEEK_DEFINES_
 #include "datecode.h"
 
-int DateCode::GetString(hchar * hstr, int slen)
+hchar_string DateCode::GetString()
 {
+    hchar_string ret;
     const hchar *fmt;
-    hchar *d;
     int i, num;
     const char *form;
     char cbuf[256];
@@ -156,8 +156,7 @@ int DateCode::GetString(hchar * hstr, int slen)
     format[DATE_SIZE - 1] = 0;
     fmt = format[0] ? format : defaultform;
 
-    d = hstr;
-    for (; *fmt && ((int) (d - hstr) < DATE_SIZE) && slen > 1; fmt++)
+    for (; *fmt && ((int) ret.size() < DATE_SIZE); fmt++)
     {
         form = (add_zero) ? "%02d" : "%d";
 
@@ -221,8 +220,7 @@ int DateCode::GetString(hchar * hstr, int slen)
                 num = date[MIN];
                 break;
             case '6':
-                *d++ = kor_week[date[WEEK]];
-                slen--;
+                ret.push_back(kor_week[date[WEEK]]);
                 break;
             case '^':
                 memcpy(cbuf, eng_week + date[WEEK] * 3, 3);
@@ -233,11 +231,8 @@ int DateCode::GetString(hchar * hstr, int slen)
                 strcpy(cbuf, en_week[date[WEEK]]);
                 break;
             case '7':
-                if (slen > 3)
-                {
-                    *d++ = 0xB5A1;
-                    *d++ = (is_pm) ? 0xD281 : 0xB8E5;
-                }
+                ret.push_back(0xB5A1);
+                ret.push_back((is_pm) ? 0xD281 : 0xB8E5);
                 break;
             case '&':
                 strcpy(cbuf, (is_pm) ? "p.m." : "a.m.");
@@ -270,28 +265,24 @@ int DateCode::GetString(hchar * hstr, int slen)
                 fmt++;
                 if (*fmt == '6')
                 {
-                    *d++ = china_week[date[WEEK]];
-                    slen--;
+                    ret.push_back(china_week[date[WEEK]]);
                     break;
                 }
                 break;
             default:
                 if (*fmt == '\\' && *++fmt == 0)
                     goto done;
-                *d++ = *fmt;
-                slen--;
+                ret.push_back(*fmt);
         }
         if (num != -1)
             sprintf(cbuf, form, num);
-        for (i = 0; 0 != cbuf[i] && slen > 1; i++)
+        for (i = 0; 0 != cbuf[i]; i++)
         {
-            *d++ = *(cbuf + i);
-            slen--;
+            ret.push_back(*(cbuf + i));
         }
     }
     done:
-    *d = 0;
-    return hstrlen(hstr);
+    return ret;
 }
 
 
@@ -432,10 +423,9 @@ Footnote::~Footnote(void)
 // Ȧ¼öÂʽÃÀÛ/°¨Ãß±â (21)
 
 // mail merge(22)
-int MailMerge::GetString(hchar * hstr, int )
+hchar_string MailMerge::GetString()
 {
-    *hstr = 0;
-    return 0;
+    return hchar_string();
 }
 
 
@@ -580,7 +570,7 @@ enum
     number´Â °ªÀÌ ±×´ë·Î µé¾î°¡ ÀÖ´Ù. Áï, 1.2.1¿¡´Â 1,2,1ÀÌ µé¾î°¡ ÀÖ´Ù.
     style Àº 1ºÎÅÍ °ªÀÌ µé¾î°¡ ÀÖ´Ù. hbox.h¿¡ Á¤ÀÇµÈ µ¥·Î..
  */
-hchar *Outline::GetUnicode(hchar * hstr, int)
+hchar_string Outline::GetUnicode() const
 {
     const hchar *p;
      hchar buffer[255];
@@ -608,14 +598,14 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
                     strcat(buf, cur_num_str);
                 }
                 str2hstr(buf, buffer);
-                     return hstr2ucsstr(buffer, hstr);
+                return hstr2ucsstr(buffer);
             }
             case OLSTY_NUMSIG1:
             case OLSTY_NUMSIG2:
             case OLSTY_NUMSIG3:
                 {
                 getOutlineNumStr(shape, level, number[level], buffer);
-                     return hstr2ucsstr(buffer, hstr);
+                return hstr2ucsstr(buffer);
                 }
             case OLSTY_BULLET1:
             case OLSTY_BULLET2:
@@ -626,7 +616,7 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
                 p = GetOutlineStyleChars(shape);
                 buffer[0] = p[level];
                 buffer[1] = 0;
-                     return hstr2ucsstr(buffer, hstr);
+                     return hstr2ucsstr(buffer);
                 }
             case OLSTY_USER:
             case OLSTY_BULUSER:
@@ -713,11 +703,11 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
                         buffer[l++] = deco[i][1];
                     }
                     buffer[l] = 0;
-                    return hstr2ucsstr(buffer, hstr);
+                    return hstr2ucsstr(buffer);
                 }
         }
     }
-     return hstr2ucsstr(buffer, hstr);
+    return hstr2ucsstr(buffer);
 }
 
 
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
index 36e1361..4fe6598 100644
--- a/hwpfilter/source/hbox.h
+++ b/hwpfilter/source/hbox.h
@@ -60,12 +60,8 @@ struct HBox
  * @returns True if reading from stream is successful.
  */
         virtual int   Read(HWPFile &hwpf);
-/**
- * @param hstr Buffer to save string
- * @param slen Size of buffer
- * @returns The string having each proper format by pointer
- */
-        virtual int   GetString(hchar *hstr, int slen = 255);
+
+        virtual hchar_string GetString();
     private:
         static int boxCount;
 };
@@ -162,10 +158,8 @@ struct DateCode: public HBox
 
     DateCode();
     virtual int Read(HWPFile &hwpf);
-/**
- * @returns Length of date string
- */
-    virtual int GetString(hchar *hstr, int slen = 255);
+
+    virtual hchar_string GetString();
 };
 
 /**
@@ -403,8 +397,8 @@ struct TxtBox: public FBox
 struct Columns
 {
      int *data;
-     int nCount;
-     int nTotal;
+     size_t nCount;
+     size_t nTotal;
      Columns(){
           nCount = 0;
           nTotal = INIT_SIZE;
@@ -414,8 +408,12 @@ struct Columns
 
      void AddColumnsSize(){
           int *tmp = data;
+          if (nTotal + ADD_AMOUNT < nTotal) // overflow
+          {
+              throw ::std::bad_alloc();
+          }
           data = new int[nTotal + ADD_AMOUNT];
-          for( int i = 0 ; i < nTotal ; i++ )
+          for (size_t i = 0 ; i < nTotal ; i++)
                 data[i] = tmp[i];
           nTotal += ADD_AMOUNT;
           delete[] tmp;
@@ -426,13 +424,13 @@ struct Columns
                 data[nCount++] = pos;
                 return;
           }
-          for( int i = 0 ; i < nCount; i++ ){
+          for (size_t i = 0 ; i < nCount; i++ ) {
                 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
                      return;  // Already exist;
                 if( pos < data[i] ){
                      if( nCount == nTotal )
                           AddColumnsSize();
-                     for( int j = nCount ; j > i ; j-- )
+                     for (size_t j = nCount ; j > i ; j--)
                           data[j] = data[j-1];
                      data[i] = pos;
                      nCount++;
@@ -449,7 +447,7 @@ struct Columns
      {
           if( pos == 0 )
                 return 0;
-          for( int i = 0 ; i < nCount; i++){
+          for (size_t i = 0 ; i < nCount; i++) {
                 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
                      return i;
           }
@@ -460,8 +458,8 @@ struct Columns
 struct Rows
 {
      int *data;
-     int nCount;
-     int nTotal;
+     size_t nCount;
+     size_t nTotal;
      Rows(){
           nCount = 0;
           nTotal = INIT_SIZE;
@@ -471,8 +469,12 @@ struct Rows
 
      void AddRowsSize(){
           int *tmp = data;
+          if (nTotal + ADD_AMOUNT < nTotal) // overflow
+          {
+              throw ::std::bad_alloc();
+          }
           data = new int[nTotal + ADD_AMOUNT];
-          for( int i = 0 ; i < nTotal ; i++ )
+          for (size_t i = 0 ; i < nTotal ; i++)
                 data[i] = tmp[i];
           nTotal += ADD_AMOUNT;
           delete[] tmp;
@@ -483,13 +485,13 @@ struct Rows
                 data[nCount++] = pos;
                 return;
           }
-          for( int i = 0 ; i < nCount; i++ ){
+          for (size_t i = 0 ; i < nCount; i++) {
                 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
                      return;  // Already exist;
                 if( pos < data[i] ){
                      if( nCount == nTotal )
                           AddRowsSize();
-                     for( int j = nCount ; j > i ; j-- )
+                     for (size_t j = nCount ; j > i ; j--)
                           data[j] = data[j-1];
                      data[i] = pos;
                      nCount++;
@@ -506,7 +508,7 @@ struct Rows
      {
           if( pos == 0 )
                 return 0;
-          for( int i = 0 ; i < nCount; i++){
+          for (size_t i = 0 ; i < nCount; i++) {
                 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
                      return i;
           }
@@ -860,7 +862,7 @@ struct MailMerge: public HBox
     MailMerge();
 
     virtual int Read(HWPFile &hwpf);
-    virtual int GetString(hchar *, int slen = 255);
+    virtual hchar_string GetString();
 };
 
 // char compositon(23)
@@ -998,7 +1000,7 @@ class Outline: public HBox
         Outline();
 
         virtual int   Read(HWPFile &hwpf);
-        hchar *GetUnicode(hchar *, int slen = 255);
+        hchar_string GetUnicode() const;
 };
 
 /* ¹­À½ ºóÄ­(30) */
diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx
index a9e9eba..bda6243 100644
--- a/hwpfilter/source/hcode.cxx
+++ b/hwpfilter/source/hcode.cxx
@@ -1178,31 +1178,28 @@ hchar ksc5601_han_to_ucs2 (hchar input)
     return '?';
 }
 
-hchar* hstr2ucsstr(hchar* hstr, hchar* ubuf)
+hchar_string hstr2ucsstr(hchar const* hstr)
 {
-  int i = 0, j;
-  int res;
-  hchar dest[3];
-  hchar *tmp = ubuf;
-  for( ; *hstr ; ){
-      res = hcharconv(*hstr++, dest, UNICODE);
-      for( j = 0 ; j < res ; j++)
-            tmp[i++] = dest[j];
-  }
-
-  tmp[i]= '\0';
-  return ubuf;
+    hchar_string ret;
+    hchar dest[3];
+    for( ; *hstr ; ){
+        int const res = hcharconv(*hstr++, dest, UNICODE);
+        for (int j = 0 ; j < res ; j++) {
+            ret.push_back(dest[j]);
+        }
+    }
+    return ret;
 }
+
 /**
  * ÇÑÄĽºÆ®¸µÀ» ¿Ï¼ºÇü½ºÆ®¸µÀ¸·Î º¯È¯ÇÑ´Ù
  */
-int hstr2ksstr(hchar* hstr, char* buf)
+::std::string hstr2ksstr(hchar const* hstr)
 {
-
-    int i = 0, res, j;
+    ::std::string ret;
+    int res, j;
     int c;
      hchar dest[3];
-    char *tmp = buf;
     for( ; *hstr ; )
     {
         res = hcharconv(*hstr++, dest, KS);
@@ -1210,17 +1207,17 @@ int hstr2ksstr(hchar* hstr, char* buf)
               c = dest[j];
               if( c < 32 ) c = ' ';
               else if( c < 256 )
-                    tmp[i++] = sal::static_int_cast<char>(c);
+              {
+                  ret.push_back(sal::static_int_cast<char>(c));
+              }
               else
               {
-                    tmp[i++] = sal::static_int_cast<char>((c >> 8 ) & 0xff);
-                    tmp[i++] = sal::static_int_cast<char>(c & 0xff);
+                  ret.push_back(sal::static_int_cast<char>((c >> 8 ) & 0xff));
+                  ret.push_back(sal::static_int_cast<char>(c & 0xff));
               }
           }
     }
-    tmp[i]= '\0';
-
-    return i;
+    return ret;
 }
 
 
@@ -1228,25 +1225,22 @@ int hstr2ksstr(hchar* hstr, char* buf)
  * Çѱۿ¡¼­ ¿µ¹®¿ÜÀÇ ¹®ÀÚ±îÁö Æ÷ÇÔÇÒ ¼ö ÀÖ´Â kcharŸÀÔÀÇ ¹®ÀÚ¿­À»
  * Çѱۿ¡¼­ »ç¿ëÇÏ´Â hcharŸÀÔÀÇ ¹®ÀÚ¿­·Î º¯È¯ÇÑ´Ù.
  */
-unsigned short *kstr2hstr( unsigned char *src, unsigned short *dest )
+hchar_string kstr2hstr(unsigned char const* src)
 {
-    int i=0, ii;
-    unsigned short* tmp = dest;
-
-    for(i=0,ii=0 ; src[i] != '\0' ; i++,ii++ )
+    hchar_string ret;
+    for (unsigned int i = 0; src[i] != '\0' ; i++)
     {
         if ( src[i] < 127 )
         {
-            tmp[ii] = src[i];
+            ret.push_back(src[i]);
         }
         else
         {
-            tmp[ii] = src[i] << 8 | src[i+1];
+            ret.push_back(src[i] << 8 | src[i+1]);
             i++;
         }
     }
-    tmp[ii] = '\0';
-    return dest;
+    return ret;
 }
 
 
@@ -1318,119 +1312,87 @@ char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar)
 }
 
 
-char *urltounix(const char *src, char *dest )
+::std::string urltounix(const char *src)
 {
+    ::std::string ret;
+    unsigned int i = 0;
     if( src[0] == 'C' && src[1] == ':' && src[2] == '\\' ) // Home Dir
     {
-        unsigned int i, len;
-        sprintf(dest,"file://%s/", getenv("HOME") );
-        len = strlen( dest );
-
-        for( i = 0 ; i + 3 < strlen(src) ; i++ )
-        {
-            if( src[i + 3] == '\\')
-                dest[i + len] = '/';
-            else
-                dest[i + len] = src[ i +3];
-        }
-        dest[i + len] = '\0';
-        return dest;
+        ret.append("file://");
+        ret.append(getenv("HOME"));
+        ret.push_back('/');
+        i = 3; // skip first 3
     }
     else if( src[0] == 'D' && src[1] == ':' && src[2] == '\\' ) // Root Dir
     {
-        unsigned int i, len;
-        sprintf(dest,"file:///");
-        len = strlen( dest );
-        for( i = 0 ; i + 3 < strlen(src) ; i++ )
-        {
-            if( src[i + 3] == '\\')
-                dest[i + len] = '/';
-            else
-                dest[i + len] = src[i+3];
-        }
-        dest[i + len] = '\0';
-        return dest;
+        ret.append("file:///");
+        i = 3; // skip first 3
     }
     else if( !strncmp(src,"http",4)  ) // Start from "http"
-     {
-        unsigned int i;
-        for( i = 0 ; i < strlen(src) ; i++ )
-        {
-            if( src[i] == '\\')
-                dest[i] = '/';
-            else
-                dest[i] = src[i];
-        }
-        dest[i] = '\0';
-        return dest;
+    {
+        // nothing special here, just copy
     }
      else
     {
-        unsigned int i, len, srclen;
-          srclen = strlen(src);
-          char ext[4];
-          strncpy(ext,src + srclen - 3,3);
-          ext[3]=0;
+        unsigned int srclen = strlen(src);
+        if (3 < srclen)
+        {
+            char const*const ext = src + (srclen-3);
 #ifdef _WIN32
-          if( _strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+            if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
 #else
-          if( strcasecmp(ext,"HWP") && strcasecmp(ext,"HWT"))
+            if (strcasecmp(ext,"HWP") && strcasecmp(ext,"HWT"))
 #endif
-              sprintf(dest, "http://");
-          len = strlen(dest);
-        for( i = 0 ; i < strlen(src) ; i++ )
-        {
-            if( src[i] == '\\')
-                dest[i+len] = '/';
-            else
-                dest[i+len] = src[i];
+            {
+                ret.append("http://");
+            }
         }
-        dest[i+len] = '\0';
-        return dest;
      }
+     for (; i < strlen(src); i++)
+     {
+        if (src[i] == '\\') {
+            ret.push_back('/');
+        } else {
+            ret.push_back(src[i]);
+        }
+     }
+     return ret;
 }
 
 #ifdef _WIN32
-char *urltowin(const char *src, char *dest )
+::std::string urltowin(const char *src)
 {
+    std::string ret;
     if( !_strnicmp(src, "http", 4))
      {
-        int i;
-        for( i = 0 ; i < sal::static_int_cast<int>(strlen(src)) ; i++ )
-        {
-            if( src[i] == '\\')
-                dest[i] = '/';
-            else
-                dest[i] = src[i];
-        }
-        dest[i] = '\0';
-        return dest;
+        // nothing special here, just copy
     }
      else
     {
-        int i, len, srclen;
-          srclen = strlen(src);
-          char ext[4];
-          strncpy(ext,src + srclen - 3,3);
-          ext[3]=0;
-          //printf("hcode.cxx : ext = %s\n",ext);
-
-          if( !_strnicmp(ext,"HWP",3) || !_strnicmp(ext,"HWT",3)){
-                strcpy(dest,src);
-                return dest;
-          }
-          sprintf(dest, "http://");
-          len = strlen(dest);
-        for( i = 0 ; i < sal::static_int_cast<int>(strlen(src)) ; i++ )
+        unsigned int srclen = strlen(src);
+        if (3 < srclen)
         {
-            if( src[i] == '\\')
-                dest[i+len] = '/';
+            char const*const ext = src + (srclen-3);
+            if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+            {
+                ret.append("http://");
+            }
             else
-                dest[i+len] = src[i];
+            {
+                ret.append(src); // no backslash conversion
+                return ret;
+            }
         }
-        dest[i+len] = '\0';
-        return dest;
-     }
+    }
+    for (unsigned int i = 0; i < strlen(src); i++)
+    {
+        if (src[i] == '\\') {
+            ret.push_back('/');
+        } else {
+            ret.push_back(src[i]);
+        }
+    }
+    return ret;
 }
 #endif
 
diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h
index 2a7f00a..d6e565d 100644
--- a/hwpfilter/source/hcode.h
+++ b/hwpfilter/source/hcode.h
@@ -35,27 +35,27 @@ DLLEXPORT int hcharconv(hchar ch, hchar *dest, int codeType) ;
 DLLEXPORT int   kssm_hangul_to_ucs2(hchar ch, hchar *dest) ;
 DLLEXPORT hchar ksc5601_han_to_ucs2 (hchar);
 DLLEXPORT hchar ksc5601_sym_to_ucs2 (hchar);
-DLLEXPORT hchar* hstr2ucsstr(hchar* hstr, hchar* ubuf);
+DLLEXPORT hchar_string hstr2ucsstr(hchar const* hstr);
 /**
  * ÇÑÄĽºÆ®¸µÀ» ¿Ï¼ºÇü½ºÆ®¸µÀ¸·Î º¯È¯ÇÑ´Ù.
  */
-DLLEXPORT int hstr2ksstr(hchar* hstr, char* buf);
+DLLEXPORT ::std::string hstr2ksstr(hchar const* hstr);
 
 /**
  * ÇѱÛÀ» Æ÷ÇÔÇÒ ¼ö ÀÖ´Â charÇü½ºÆ®¸µÀ» ÇÑÄĽºÆ®¸µÀ¸·Î º¯È¯ÇÑ´Ù.
  */
-DLLEXPORT hchar *kstr2hstr( uchar *src, hchar *dest );
+DLLEXPORT hchar_string kstr2hstr(uchar const* src);
 
 /**
  * hwpÀÇ °æ·Î¸¦ unixÇüÅ·Π¹Ù²Û´Ù.
  */
-DLLEXPORT char *urltounix(const char *src, char *buf );
+DLLEXPORT ::std::string urltounix(const char *src);
 
 /**
  * hwpÀÇ °æ·Î¸¦ windowsÇüÅ·Π¹Ù²Û´Ù.
  */
 #ifdef _WIN32
-DLLEXPORT char *urltowin(const char *src, char *buf );
+DLLEXPORT ::std::string urltowin(const char *src);
 #endif
 /**
  *  Transfer interger to string following format
diff --git a/hwpfilter/source/himgutil.cxx b/hwpfilter/source/himgutil.cxx
deleted file mode 100644
index b3e969b..0000000
--- a/hwpfilter/source/himgutil.cxx
+++ /dev/null
@@ -1,163 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "precompile.h"
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "hwplib.h"
-#include "htags.h"
-#include "himgutil.h"
-
-
-static int ImageMagicType(const uchar * magicno)
-{
-    int rv = RFT_UNKNOWN;
-
-    if (strncmp((char *) magicno, "GIF87a", 6) == 0 ||
-        strncmp((char *) magicno, "GIF89a", 6) == 0)
-        rv = RFT_GIF;
-    else if (strncmp((char *) magicno, "VIEW", 4) == 0 ||
-        strncmp((char *) magicno, "WEIV", 4) == 0)
-        rv = RFT_PM;
-    else if (magicno[0] == 'P' && magicno[1] >= '1' && magicno[1] <= '6')
-        rv = RFT_PBM;
-/* note: have to check XPM before XBM, as first 2 chars are the same */
-    else if (strncmp((char *) magicno, "/* XPM */", 9) == 0)
-        rv = RFT_XPM;
-    else if (strncmp((char *) magicno, "#define", 7) == 0 ||
-        (magicno[0] == '/' && magicno[1] == '*'))
-        rv = RFT_XBM;
-    else if (magicno[0] == 0x59 && (magicno[1] & 0x7f) == 0x26 &&
-        magicno[2] == 0x6a && (magicno[3] & 0x7f) == 0x15)
-        rv = RFT_SUNRAS;
-    else if (magicno[0] == 'B' && magicno[1] == 'M')
-        rv = RFT_BMP;
-    else if (magicno[0] == 0x52 && magicno[1] == 0xcc)
-        rv = RFT_UTAHRLE;
-    else if ((magicno[0] == 0x01 && magicno[1] == 0xda) ||
-        (magicno[0] == 0xda && magicno[1] == 0x01))
-        rv = RFT_IRIS;
-    else if (magicno[0] == 0x1f && magicno[1] == 0x9d)
-        rv = RFT_COMPRESS;
-    else if (magicno[0] == 0x0a && magicno[1] <= 5)
-        rv = RFT_PCX;
-    else if (strncmp((char *) magicno, "FORM", 4) == 0 &&
-        strncmp((char *) magicno + 8, "ILBM", 4) == 0)
-        rv = RFT_IFF;
-    else if (magicno[0] == 0 && magicno[1] == 0 &&
-        magicno[2] == 2 && magicno[3] == 0 &&
-        magicno[4] == 0 && magicno[5] == 0 &&
-        magicno[6] == 0 && magicno[7] == 0)
-        rv = RFT_TARGA;
-    else if (magicno[4] == 0x00 && magicno[5] == 0x00 &&
-        magicno[6] == 0x00 && magicno[7] == 0x07)
-        rv = RFT_XWD;
-    else if (strncmp((char *) magicno, "SIMPLE  ", 8) == 0 &&
-        magicno[29] == 'T')
-        rv = RFT_FITS;
-    else if (magicno[0] == 0xff && magicno[1] == 0xd8 && magicno[2] == 0xff)
-        rv = RFT_JFIF;
-    else if ((magicno[0] == 'M' && magicno[1] == 'M') ||
-        (magicno[0] == 'I' && magicno[1] == 'I'))
-        rv = RFT_TIFF;
-    else if (strncmp((char *) magicno, "%!", 2) == 0 ||
-        strncmp((char *) magicno, "\004%!", 3) == 0)
-        rv = RFT_PS;
-    else if (strncmp((char *) magicno, "\xd7\xcd\xc6\x9a", 4) == 0 ||
-        strncmp((char *) magicno, "\x01\x00\x09\x00\x00\x03", 6) == 0)
-        rv = RFT_WMF;
-
-    return rv;
-}
-
-const char *GetEmbImgname(const EmPicture * empic)
-{
-    static char fname[256];
-    char *ptr;
-    const char *ext;
-
-    if (tmpnam(fname) == NULL)
-        return NULL;
-    if (!empic || !empic->name[0] || (0 == (ptr = strrchr(fname, DIRSEP))))
-        return NULL;
-    switch (ImageMagicType((uchar *) empic->data))
-    {
-        case RFT_GIF:
-            ext = "gif";
-            break;
-        case RFT_PM:
-            ext = "pm";
-            break;
-        case RFT_PBM:
-            ext = "pbm";
-            break;
-        case RFT_XBM:
-            ext = "xbm";
-            break;
-        case RFT_SUNRAS:
-            ext = "ras";
-            break;
-        case RFT_BMP:
-            ext = "bmp";
-            break;
-        case RFT_UTAHRLE:
-            ext = "rle";
-            break;
-        case RFT_PCX:
-            ext = "pcx";
-            break;
-        case RFT_JFIF:
-            ext = "jpg";
-            break;
-        case RFT_TIFF:
-            ext = "tif";
-            break;
-        case RFT_PDSVICAR:
-            ext = "pds";
-            break;
-        case RFT_PS:
-            ext = "ps";
-            break;
-        case RFT_IFF:
-            ext = "iff";
-            break;
-        case RFT_TARGA:
-            ext = "tga";
-            break;
-        case RFT_XPM:
-            ext = "xpm";
-            break;
-        case RFT_XWD:
-            ext = "xwd";
-            break;
-        case RFT_WMF:
-            ext = "wmf";
-            break;
-        default:
-            ext = "666";
-            break;
-    };
-    sprintf(ptr + 1, "mz_%s.%s", empic->name,ext);
-    return fname;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/himgutil.h b/hwpfilter/source/himgutil.h
deleted file mode 100644
index f54eef0..0000000
--- a/hwpfilter/source/himgutil.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef _HIMGUTIL_H_
-#define _HIMGUTIL_H_
-
-/**
- * Graphics file format identifiers.
- */
-#define RFT_ERROR    -1                           /* couldn't open file, or whatever... */
-#define RFT_UNKNOWN   0
-#define RFT_GIF       1
-#define RFT_PM        2
-#define RFT_PBM       3
-#define RFT_XBM       4
-#define RFT_SUNRAS    5
-#define RFT_BMP       6
-#define RFT_UTAHRLE   7
-#define RFT_IRIS      8
-#define RFT_PCX       9
-#define RFT_JFIF     10
-#define RFT_TIFF     11
-#define RFT_PDSVICAR 12
-#define RFT_COMPRESS 13
-#define RFT_PS       14
-#define RFT_IFF      15
-#define RFT_TARGA    16
-#define RFT_XPM      17
-#define RFT_XWD      18
-#define RFT_FITS     19
-#define RFT_WMF      20
-
-// function declaration
-struct EmPicture;
-
-/**
- * Extract the name from given object
- * @param empic Object having name to extract
- * @returns Name of embeded picture
- */
-const char *GetEmbImgname(const EmPicture *empic);
-#endif                                            /* _HIMGUTIL_H_ */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 3e83c32..68e3136 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -21,6 +21,8 @@
 
 #include <osl/diagnose.h>
 
+#include <comphelper/newarray.hxx>
+
 #include "hwplib.h"
 #include "hwpfile.h"
 #include "hpara.h"
@@ -110,7 +112,8 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
           pshape.pagebreak = etcflag;
     }
 
-    linfo = new LineInfo[nline];
+    linfo = ::comphelper::newArray_null<LineInfo>(nline);
+    if (!linfo) { return false; }
     for (ii = 0; ii < nline; ii++)
     {
         linfo[ii].Read(hwpf, this);
@@ -137,7 +140,7 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
 
     if (contain_cshape)
     {
-        cshapep = new CharShape[nch];
+        cshapep = ::comphelper::newArray_null<CharShape>(nch);
         if (!cshapep)
         {
             perror("Memory Allocation: cshape\n");
@@ -161,7 +164,8 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
         }
     }
 // read string
-    hhstr = new HBox *[nch];
+    hhstr = ::comphelper::newArray_null<HBox *>(nch);
+    if (!hhstr) { return false; }
     for (ii = 0; ii < nch; ii++)
         hhstr[ii] = 0;
     ii = 0;
diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx
index 1e1a559..25d7894 100644
--- a/hwpfilter/source/hstyle.cxx
+++ b/hwpfilter/source/hstyle.cxx
@@ -19,6 +19,8 @@
 
 #include "precompile.h"
 
+#include <comphelper/newarray.hxx>
+
 #include    "hwplib.h"
 #include    "hwpfile.h"
 #include    "hstyle.h"
@@ -123,7 +125,7 @@ bool HWPStyle::Read(HWPFile & hwpf)
     ParaShape pshape;
 
     hwpf.Read2b(&nstyles, 1);
-    style = new StyleData[nstyles];
+    style = ::comphelper::newArray_null<StyleData>(nstyles);
     if (!style)
         return false;
 
diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx
index 8bab8da..938df44 100644
--- a/hwpfilter/source/htags.cxx
+++ b/hwpfilter/source/htags.cxx
@@ -24,7 +24,6 @@
 #include "hwplib.h"
 #include "hwpfile.h"
 #include "htags.h"
-#include "himgutil.h"
 
 bool HyperText::Read(HWPFile & hwpf)
 {
@@ -59,11 +58,6 @@ EmPicture::EmPicture(size_t tsize)
 #endif
 EmPicture::~EmPicture(void)
 {
-// clear temporary image file
-    char *fname = (char *) GetEmbImgname(this);
-
-    if (fname && access(fname, 0) == 0)
-        unlink(fname);
     if (data)
         delete[]data;
 };
diff --git a/hwpfilter/source/hwplib.h b/hwpfilter/source/hwplib.h
index f6c86bd..da8a253 100644
--- a/hwpfilter/source/hwplib.h
+++ b/hwpfilter/source/hwplib.h
@@ -20,6 +20,9 @@
 #ifndef _HWPLIB_H_
 #define _HWPLIB_H_
 #include "precompile.h"
+
+#include <string>
+
 /* hwp96ºÎÅÍ hunit°¡ 4byte°¡ µÇ¾ú´Ù. */
 /**
  * size of hunit is 4 since hwp96 version
@@ -50,6 +53,8 @@ typedef unsigned int    uint;
 typedef unsigned long   ulong;
 #endif                                            /* _UTYPE_ */
 
+typedef ::std::basic_string<hchar> hchar_string;
+
 #ifndef _ZZRECT_
 #define _ZZRECT_
 /**
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx
index 557457f..325f74c 100644
--- a/hwpfilter/source/hwpread.cxx
+++ b/hwpfilter/source/hwpread.cxx
@@ -19,6 +19,8 @@
 
 #include "precompile.h"
 
+#include <comphelper/newarray.hxx>
+
 #include <list>
 
 #include "hwpfile.h"
@@ -77,20 +79,30 @@ int FieldCode::Read(HWPFile & hwpf)
     hwpf.Read4b(&len3, 1);
     hwpf.Read4b(&binlen, 1);
 
-    str1 = new hchar[len1];
-    str2 = new hchar[len2];
-    str3 = new hchar[len3];
+    ulong const len1_ = ((len1 > 1024) ? 1024 : len1) / sizeof(hchar);
+    ulong const len2_ = ((len2 > 1024) ? 1024 : len2) / sizeof(hchar);
+    ulong const len3_ = ((len3 > 1024) ? 1024 : len3) / sizeof(hchar);
+
+    str1 = new hchar[len1_ ? len1_ : 1];
+    str2 = new hchar[len2_ ? len2_ : 1];
+    str3 = new hchar[len3_ ? len3_ : 1];
     bin = new char[binlen];
 
-    hwpf.Read2b(str1, len1/2);
-    hwpf.Read2b(str2, len2/2);
-    hwpf.Read2b(str3, len3/2);
+    hwpf.Read2b(str1, len1_);
+    hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
+    str1[len1_ ? (len1_ - 1) : 0] = 0;
+    hwpf.Read2b(str2, len2_);
+    hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
+    str2[len2_ ? (len2_ - 1) : 0] = 0;
+    hwpf.Read2b(str3, len3_);
+    hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
+    str3[len3_ ? (len3_ - 1) : 0] = 0;
 
     hwpf.ReadBlock(bin, binlen);
 
      if( type[0] == 3 && type[1] == 2 ){ /* ¸¸µç³¯Â¥·Î¼­ Æ÷¸ËÀ» »ý¼ºÇØ¾ß ÇÑ´Ù. */
           DateCode *pDate = new DateCode;
-          for( int i = 0 ;i < (int)(len3/2) ; i++ ){
+          for (int i = 0 ; i < static_cast<int>(len3_); i++) {
                 if(str3[i] == 0 ) break;
                 if( i >= DATE_SIZE ) break;
                 pDate->format[i] = str3[i];
@@ -277,7 +289,10 @@ int TxtBox::Read(HWPFile & hwpf)
         return hwpf.SetState(HWP_InvalidFileFormat);
      }
 
-    cell = new Cell[ncell];
+    cell = ::comphelper::newArray_null<Cell>(ncell);
+    if (!cell) {
+        return hwpf.SetState(HWP_InvalidFileFormat);
+    }
     for (ii = 0; ii < ncell; ii++)
     {
         cell[ii].Read(hwpf);
@@ -285,7 +300,10 @@ int TxtBox::Read(HWPFile & hwpf)
     }
     if (ncell == 1)
         style.cell = &cell[0];
-    plists = new std::list < HWPPara* >[ncell];
+    plists = ::comphelper::newArray_null< std::list< HWPPara* > >(ncell);
+    if (!plists) {
+        return hwpf.SetState(HWP_InvalidFileFormat);
+    }
     for (ii = 0; ii < ncell; ii++)
         hwpf.ReadParaList(plists[ii]);
      // caption
@@ -300,7 +318,10 @@ int TxtBox::Read(HWPFile & hwpf)
                 tbl->rows.insert(cell[ii].y);
                 tbl->rows.insert(cell[ii].y + cell[ii].h);
           }
-          TCell* *pArr = new TCell*[ncell];
+          TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell);
+          if (!pArr) {
+                return hwpf.SetState(HWP_InvalidFileFormat);
+          }
           for( ii = 0 ; ii < ncell; ii++)
           {
                 TCell *tcell = new TCell;
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 58dffb2..d14ef99 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -23,6 +23,9 @@
 
 #include "hwpreader.hxx"
 #include <math.h>
+
+#include <comphelper/newarray.hxx>
+
 #include "formula.h"
 #include "cspline.h"
 
@@ -37,7 +40,7 @@ extern int getRepFamilyName(const char* , char *, double &ratio);
 #endif
 
 // To be shorten source code by realking
-#define hconv(x,y) OUString(hstr2ucsstr(x,y))
+#define hconv(x)        OUString(hstr2ucsstr(x).c_str())
 #define ascii(x)        OUString::createFromAscii(x)
 #define rstartEl(x,y)   do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(0)
 #define rendEl(x)       do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(0)
@@ -70,8 +73,6 @@ extern int getRepFamilyName(const char* , char *, double &ratio);
     rendEl(ascii("text:span")); \
     tstart = false
 
-static hchar gstr[1024];
-static hchar sbuf[256];
 static hchar *field = 0L;
 static char buf[1024];
 
@@ -246,21 +247,21 @@ void HwpReader::makeMeta()
     if (hwpinfo->summary.title[0])
     {
         rstartEl(ascii("dc:title"), rList);
-        rchars((hconv(hwpinfo->summary.title, gstr)));
+        rchars((hconv(hwpinfo->summary.title)));
         rendEl(ascii("dc:title"));
     }
 
     if (hwpinfo->summary.subject[0])
     {
         rstartEl(ascii("dc:subject"), rList);
-        rchars((hconv(hwpinfo->summary.subject, gstr)));
+        rchars((hconv(hwpinfo->summary.subject)));
         rendEl(ascii("dc:subject"));
     }
 
     if (hwpinfo->summary.author[0])
     {
         rstartEl(ascii("meta:initial-creator"), rList);
-        rchars((hconv(hwpinfo->summary.author, gstr)));
+        rchars((hconv(hwpinfo->summary.author)));
         rendEl(ascii("meta:initial-creator"));
     }
 
@@ -334,31 +335,31 @@ void HwpReader::makeMeta()
         if (hwpinfo->summary.keyword[0][0])
         {
             rstartEl(ascii("meta:keyword"), rList);
-            rchars((hconv(hwpinfo->summary.keyword[0], gstr)));
+            rchars((hconv(hwpinfo->summary.keyword[0])));
             rendEl(ascii("meta:keyword"));
         }
         if (hwpinfo->summary.keyword[1][0])
         {
             rstartEl(ascii("meta:keyword"), rList);
-            rchars((hconv(hwpinfo->summary.keyword[1], gstr)));
+            rchars((hconv(hwpinfo->summary.keyword[1])));
             rendEl(ascii("meta:keyword"));
         }
         if (hwpinfo->summary.etc[0][0])
         {
             rstartEl(ascii("meta:keyword"), rList);
-            rchars((hconv(hwpinfo->summary.etc[0], gstr)));
+            rchars((hconv(hwpinfo->summary.etc[0])));
             rendEl(ascii("meta:keyword"));
         }
         if (hwpinfo->summary.etc[1][0])
         {
             rstartEl(ascii("meta:keyword"), rList);
-            rchars((hconv(hwpinfo->summary.etc[1], gstr)));
+            rchars((hconv(hwpinfo->summary.etc[1])));
             rendEl(ascii("meta:keyword"));
         }
         if (hwpinfo->summary.etc[2][0])
         {
             rstartEl(ascii("meta:keyword"), rList);
-            rchars((hconv(hwpinfo->summary.etc[2], gstr)));
+            rchars((hconv(hwpinfo->summary.etc[2])));
             rendEl(ascii("meta:keyword"));
         }
         rendEl(ascii("meta:keywords"));
@@ -504,7 +505,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
                 if( !prop->pictype )
                 {
                     padd( ascii("xlink:href"), sXML_CDATA,
-                        hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile, buf), sbuf), gstr));
+                        hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
                 }
                 else
                 {
@@ -513,7 +514,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
                         emp = hwpfile.GetEmPictureByName(prop->szPatternFile);
                     if( emp )
                     {
-                        char filename[128];
+                        char filename[128+17+9];
                         char dirname[128];
                         int fd;
 #ifdef _WIN32
@@ -547,7 +548,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
                     else
                     {
                         padd( ascii("xlink:href"), sXML_CDATA,
-                            hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile, buf), sbuf), gstr));
+                            hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
                     }
 
                 }
@@ -728,7 +729,7 @@ void HwpReader::makeStyles()
     for (int ii = 0; ii < hwpstyle->Num(); ii++)
     {
         unsigned char *stylename = (unsigned char *) hwpstyle->GetName(ii);
-        padd(ascii("style:name"), sXML_CDATA, (hconv(kstr2hstr(stylename, sbuf), gstr)));
+        padd(ascii("style:name"), sXML_CDATA, (hconv(kstr2hstr(stylename).c_str())));
         padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
         padd(ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
 
@@ -1326,10 +1327,10 @@ void HwpReader::parseCharShape(CharShape * cshape)
     padd(ascii("style:font-size-asian"), sXML_CDATA,
         ascii(Int2Str(cshape->size / 25, "%dpt", buf)));
 
-    char tmp[128];
-    hstr2ksstr(kstr2hstr((unsigned char *) hwpfont->GetFontName(0, cshape->font[0]), sbuf), tmp);
+    ::std::string const tmp = hstr2ksstr(kstr2hstr(
+        (unsigned char *) hwpfont->GetFontName(0, cshape->font[0])).c_str());
     double fRatio = 1.0;
-    int size = getRepFamilyName(tmp,buf, fRatio);
+    int size = getRepFamilyName(tmp.c_str(), buf, fRatio);
 
     padd(ascii("fo:font-family"), sXML_CDATA,
         OUString(buf, size, RTL_TEXTENCODING_EUC_KR));
@@ -1710,10 +1711,10 @@ void HwpReader::makePageStyle()
              if( hwpinfo->back_info.type == 1 ){
 #ifdef _WIN32
                  padd(ascii("xlink:href"), sXML_CDATA,
-                      hconv(kstr2hstr((uchar *) urltowin(hwpinfo->back_info.filename, buf), sbuf), gstr));
+                      hconv(kstr2hstr((uchar*) urltowin(hwpinfo->back_info.filename).c_str()).c_str()));
 #else
                  padd(ascii("xlink:href"), sXML_CDATA,
-                    hconv(kstr2hstr( (uchar *)urltounix(hwpinfo->back_info.filename, buf), sbuf), gstr));
+                    hconv(kstr2hstr( (uchar *)urltounix(hwpinfo->back_info.filename).c_str()).c_str()));
 #endif
                  padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
                  padd(ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
@@ -1874,10 +1875,9 @@ void HwpReader::makeTableStyle(Table *tbl)
     rendEl(ascii("style:style"));
 
 // --------------- column ---------------- //
-    int i ;
-    for( i = 0 ; i < tbl->columns.nCount -1 ; i++ )
+    for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
     {
-        sprintf(buf,"Table%d.%c",hbox->style.boxnum, 'A'+i);
+        sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
         padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
         padd(ascii("style:family"), sXML_CDATA,ascii("table-column"));
         rstartEl(ascii("style:style"), rList);
@@ -1891,9 +1891,9 @@ void HwpReader::makeTableStyle(Table *tbl)
     }
 
 // --------------- row ---------------- //
-    for( i = 0 ; i < tbl->rows.nCount -1 ; i++ )
+    for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++)
     {
-        sprintf(buf,"Table%d.row%d",hbox->style.boxnum, i + 1);
+        sprintf(buf,"Table%d.row%ld",hbox->style.boxnum, i + 1);
         padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
         padd(ascii("style:family"), sXML_CDATA,ascii("table-row"));
         rstartEl(ascii("style:style"), rList);
@@ -1907,7 +1907,7 @@ void HwpReader::makeTableStyle(Table *tbl)
     }
 
 // --------------- cell --------------------- //
-    for( i = 0 ; i < (int)tbl->cells.size(); i++ )
+    for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
     {
 	std::list<TCell*>::iterator it = tbl->cells.begin();
 
@@ -2691,13 +2691,10 @@ char *HwpReader::getPStyleName(int index, char *_buf)
 }
 
 
-void HwpReader::makeChars(hchar *str, int size)
+void HwpReader::makeChars(hchar_string & rStr)
 {
-    if (size)
-    {
-        str[size] = '\0';
-        rchars(OUString(str));
-    }
+    rchars(OUString(rStr.c_str()));
+    rStr.clear();
 }
 
 
@@ -2706,8 +2703,9 @@ void HwpReader::makeChars(hchar *str, int size)
  */
 void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
 {
+    hchar_string str;
     int n;
-    int l = 0, res;
+    int res;
      hchar dest[3];
     unsigned char firstspace = 0;
     if( !bParaStart)
@@ -2741,15 +2739,13 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
     {
         if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
         {
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rstartEl(ascii("text:s"), rList);
             rendEl(ascii("text:s"));
         }
         else if (para->hhstr[n]->hh == CH_END_PARA)
         {
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rendEl(ascii("text:span"));
             rendEl(ascii("text:p"));
             break;
@@ -2762,7 +2758,9 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
                 firstspace = 1;
                 res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
                 for( int j = 0 ; j < res; j++ )
-                    gstr[l++] =  dest[j];
+                {
+                    str.push_back(dest[j]);
+                }
         }
     }
 }
@@ -2773,8 +2771,9 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
  */
 void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
 {
+    hchar_string str;
     int n;
-    int l = 0, res;
+    int res;
      hchar dest[3];
     int curr = para->cshape.index;
     unsigned char firstspace = 0;
@@ -2811,8 +2810,7 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
     {
         if (para->GetCharShape(n)->index != curr)
         {
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rendEl(ascii("text:span"));
             curr = para->GetCharShape(n)->index;
             padd(ascii("text:style-name"), sXML_CDATA,
@@ -2822,15 +2820,13 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
         }
         if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
         {
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rstartEl(ascii("text:s"), rList);
             rendEl(ascii("text:s"));
         }
         else if (para->hhstr[n]->hh == CH_END_PARA)
         {
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rendEl(ascii("text:span"));
             rendEl(ascii("text:p"));
             break;
@@ -2845,7 +2841,9 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
                 firstspace = 1;
                 res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
                 for( int j = 0 ; j < res; j++ )
-                    gstr[l++] =  dest[j];
+                {
+                    str.push_back(dest[j]);
+                }
         }
     }
 }
@@ -2856,9 +2854,9 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
  */
 void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
 {
+    hchar_string str;
     int n, res;
      hchar dest[3];
-    size_t l = 0;
     unsigned char firstspace = 0;
     bool pstart = bParaStart;
     bool tstart = false;
@@ -2888,12 +2886,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
     {
         if( para->hhstr[n]->hh == CH_END_PARA )
         {
-            if( l > 0 )
+            if (str.size() > 0)
             {
                 if( !pstart ){ STARTP;}
                 if( !tstart ){ STARTT;}
-                makeChars(gstr, l);
-                l = 0;
+                makeChars(str);
             }
             if( tstart ){ ENDT;}
             if( !pstart ){ STARTP;}
@@ -2904,8 +2901,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
         {
             if( !pstart ) {STARTP;}
             if( !tstart ) {STARTT;}
-            makeChars(gstr, l);
-            l = 0;
+            makeChars(str);
             rstartEl(ascii("text:s"), rList);
             pList->clear();
             rendEl(ascii("text:s"));
@@ -2917,9 +2913,8 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                     {
                          if( !pstart ) {STARTP;}
                          if( !tstart ) {STARTT;}
-                         makeChars(gstr, l);
+                         makeChars(str);
                          ENDT;
-                         l = 0;
                     }
             if( para->hhstr[n]->hh == CH_SPACE )
                 firstspace = 0;
@@ -2927,7 +2922,9 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 firstspace = 1;
                 res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
                 for( int j = 0 ; j < res; j++ )
-                    gstr[l++] =  dest[j];
+                {
+                    str.push_back(dest[j]);
+                }
         }
         else if (para->hhstr[n]->hh == CH_FIELD)
         {
@@ -2936,15 +2933,14 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
             {
                 if( !pstart ) {STARTP;}
                 if( !tstart ) {STARTT;}
-                makeChars(gstr, l);
-                l = 0;
+                makeChars(str);
                 firstspace = 1;
                      if( hbox->type[0] == 4 && hbox->type[1] == 0 )
                      {
                          field = hbox->str3;
                      }
                      else{
-                         makeFieldCode(hbox);
+                         makeFieldCode(str, hbox);
                      }
                 infield = true;
             }
@@ -2953,12 +2949,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 firstspace = 1;
                      if( hbox->type[0] == 4 && hbox->type[1] == 0 )
                      {
-                         gstr[l] = 0;
-                         makeFieldCode(hbox);
+                         makeFieldCode(str, hbox);
                          field = 0L;
                      }
                 infield = false;
-                l = 0;
+                str.clear();
             }
         }
         else
@@ -2968,8 +2963,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_BOOKMARK:
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeBookmark((Bookmark *) para->hhstr[n]);
                     break;
                 case CH_DATE_FORM:                // 7
@@ -2977,17 +2971,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_DATE_CODE:                // 8
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeDateCode((DateCode *) para->hhstr[n]);
                     break;
                 case CH_TAB:                      // 9
                     if( !pstart ) {STARTP;}
-                    if( l > 0 )
+                    if (str.size() > 0)
                     {
                         if( !tstart ) {STARTT;}
-                        makeChars(gstr, l);
-                        l = 0;
+                        makeChars(str);
                     }
                     makeTab((Tab *) para->hhstr[n]);
                     break;
@@ -3000,17 +2992,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                     {
                         if( !pstart ) {STARTP;}
                         if( !tstart ) {STARTT;}
-                        makeChars(gstr, l);
-                        l = 0;
+                        makeChars(str);
                     }
                     else
                     {
                         if( !pstart ) {STARTP;}
-                        if( l > 0 )
+                        if (str.size() > 0)
                         {
                             if( !tstart ) {STARTT;}
-                            makeChars(gstr, l);
-                            l = 0;
+                            makeChars(str);
                         }
                         if( tstart ) {ENDT;}
                     }
@@ -3035,17 +3025,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                     {
                         if( !pstart ) {STARTP;}
                         if( !tstart ) {STARTT;}
-                        makeChars(gstr, l);
-                        l = 0;
+                        makeChars(str);
                     }
                     else
                     {
                         if( !pstart ) {STARTP;}
-                        if( l > 0 )
+                        if (str.size() > 0)
                         {
                             if( !tstart ) {STARTT;}
-                            makeChars(gstr, l);
-                            l = 0;
+                            makeChars(str);
                         }
                         if( tstart ) {ENDT;}
                     }
@@ -3055,12 +3043,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_LINE:                     // 14
                 {
                     Line *hbox = (Line *) para->hhstr[n];
-                    if( l > 0 )
+                    if (str.size() > 0)
                     {
                         if( !pstart ) {STARTP;}
                         if( !tstart ) {STARTT;}
-                        makeChars(gstr, l);
-                        l = 0;
+                        makeChars(str);
                     }
                     if( tstart ) {ENDT;}
                     if( pstart ) {ENDP;}
@@ -3071,22 +3058,19 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_HIDDEN:                   // 15
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeHidden((Hidden *) para->hhstr[n]);
                     break;
                 case CH_FOOTNOTE:                 // 17
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeFootnote((Footnote *) para->hhstr[n]);
                     break;
                 case CH_AUTO_NUM:                 // 18
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeAutoNum((AutoNum *) para->hhstr[n]);
                     break;
                 case CH_NEW_NUM:                  // 19 -skip
@@ -3096,8 +3080,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_MAIL_MERGE:               // 22
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeMailMerge((MailMerge *) para->hhstr[n]);
                     break;
                 case CH_COMPOSE:                  /* 23 - 글자겹침 */
@@ -3107,27 +3090,24 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
                 case CH_TOC_MARK:                 /* 25 아래의 3개는 작업해야 한다. */
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeTocMark((TocMark *) para->hhstr[n]);
                     break;
                 case CH_INDEX_MARK:               // 26
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeIndexMark((IndexMark *) para->hhstr[n]);
                     break;
                 case CH_OUTLINE:                  // 28
                     if( !pstart ) {STARTP;}
                     if( !tstart ) {STARTT;}
-                    makeChars(gstr, l);
-                    l = 0;
+                    makeChars(str);
                     makeOutline((Outline *) para->hhstr[n]);
                     break;
                      case CH_FIXED_SPACE:
                      case CH_KEEP_SPACE:
-                          gstr[l++] = 0x0020;
+                          str.push_back(0x0020);
                           break;
                 }
         }
@@ -3135,108 +3115,108 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
 }
 
 
-void HwpReader::makeFieldCode(FieldCode *hbox)
+void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
 {
 /* 누름틀 */
     if( hbox->type[0] == 4 && hbox->type[1] == 0 )
     {
         padd(ascii("text:placeholder-type"), sXML_CDATA, ascii("text"));
           if( field )
-              padd(ascii("text:description"), sXML_CDATA, hconv(field, sbuf));
+              padd(ascii("text:description"), sXML_CDATA, hconv(field));
         rstartEl( ascii("text:placeholder"), rList);
         pList->clear();
-        rchars( OUString(gstr));
+        rchars( OUString(rStr.c_str()));
         rendEl( ascii("text:placeholder") );
     }
 /* 문서요약 */
     else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
     {
-        if( hconv( hbox->str3, gstr ) == "title" )
+        if (hconv(hbox->str3) == "title")
         {
             rstartEl( ascii("text:title"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:title") );
         }
-        else if( hconv( hbox->str3, gstr ) == "subject" )
+        else if (hconv(hbox->str3) == "subject")
         {
             rstartEl( ascii("text:subject"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:subject") );
         }
-        else if( hconv( hbox->str3, gstr ) == "author" )
+        else if (hconv(hbox->str3) == "author")
         {
             rstartEl( ascii("text:author-name"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:author-name") );
         }
-        else if( hconv( hbox->str3, gstr ) == "keywords" )
+        else if (hconv(hbox->str3) == "keywords")
         {
             rstartEl( ascii("text:keywords"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:keywords") );
         }
     }
 /* 개인정보 */
     else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
     {
-        if( hconv( hbox->str3, gstr ) == "User" )
+        if (hconv(hbox->str3) == "User")
         {
             rstartEl( ascii("text:sender-lastname"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-lastname") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Company" )
+        else if (hconv(hbox->str3) == "Company")
         {
             rstartEl( ascii("text:sender-company"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-company") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Position" )
+        else if (hconv(hbox->str3) == "Position")
         {
             rstartEl( ascii("text:sender-title"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-title") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Division" )
+        else if (hconv(hbox->str3) == "Division")
         {
             rstartEl( ascii("text:sender-position"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-position") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Fax" )
+        else if (hconv(hbox->str3) == "Fax")
         {
             rstartEl( ascii("text:sender-fax"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-fax") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Pager" )
+        else if (hconv(hbox->str3) == "Pager")
         {
             rstartEl( ascii("text:phone-private"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:phone-private") );
         }
-        else if( hconv( hbox->str3, gstr ) == "E-mail" )
+        else if (hconv(hbox->str3) == "E-mail")
         {
             rstartEl( ascii("text:sender-email"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-email") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Zipcode(office)" )
+        else if (hconv(hbox->str3) == "Zipcode(office)")
         {
             rstartEl( ascii("text:sender-postal-code"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-postal-code") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Phone(office)" )
+        else if (hconv(hbox->str3) == "Phone(office)")
         {
             rstartEl( ascii("text:sender-phone-work"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-phone-work") );
         }
-        else if( hconv( hbox->str3, gstr ) == "Address(office)" )
+        else if (hconv(hbox->str3) == "Address(office)")
         {
             rstartEl( ascii("text:sender-street"), rList );
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:sender-street") );
         }
 
@@ -3248,7 +3228,7 @@ void HwpReader::makeFieldCode(FieldCode *hbox)
                      ascii(Int2Str(hbox->m_pDate->key, "N%d", buf)));
             rstartEl( ascii("text:creation-date"), rList );
             pList->clear();
-            rchars(  hconv(hbox->str2, gstr) );
+            rchars(  hconv(hbox->str2) );
             rendEl( ascii("text:creation-date") );
      }
 }
@@ -3262,21 +3242,21 @@ void HwpReader::makeBookmark(Bookmark * hbox)
 {
     if (hbox->type == 0)
     {
-        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
         rstartEl(ascii("text:bookmark"), rList);
         pList->clear();
         rendEl(ascii("text:bookmark"));
     }
     else if (hbox->type == 1)                     /* 블록 북마크일 경우 시작과 끝이 있다 */
     {
-        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
         rstartEl(ascii("text:bookmark-start"), rList);
         pList->clear();
         rendEl(ascii("text:bookmark-start"));
     }
     else if (hbox->type == 2)
     {
-        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+        padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
         rstartEl(ascii("text:bookmark-end"), rList);
         pList->clear();
         rendEl(ascii("text:bookmark-end"));
@@ -3420,10 +3400,11 @@ void HwpReader::makeDateFormat(DateCode * hbox)
             case '~':                             // Chinese Locale
                 break;
             default:
+                hchar sbuf[2];
                 sbuf[0] = *fmt;
                 sbuf[1] = 0;
                 rstartEl(ascii("number:text"), rList);
-                rchars((hconv(sbuf, gstr)));
+                rchars((hconv(sbuf)));
                 rendEl(ascii("number:text"));
                 break;
         }
@@ -3439,8 +3420,8 @@ void HwpReader::makeDateCode(DateCode * hbox)
         ascii(Int2Str(hbox->key, "N%d", buf)));
     rstartEl( ascii("text:date"), rList );
     pList->clear();
-    hbox->GetString(sbuf, 255);
-    rchars((hconv(sbuf, gstr)));
+    hchar_string const boxstr = hbox->GetString();
+    rchars((hconv(boxstr.c_str())));
     rendEl( ascii("text:date") );
 }
 
@@ -3463,10 +3444,9 @@ void HwpReader::makeTable(TxtBox * hbox)
 
     Table *tbl = hbox->m_pTable;
 // ----------- column ---------------- //
-    int i ;
-    for( i = 0 ; i < tbl->columns.nCount -1 ; i++ )
+    for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
     {
-        sprintf(buf,"Table%d.%c",hbox->style.boxnum, 'A'+i);
+        sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
         padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
         rstartEl(ascii("table:table-column"), rList);
         pList->clear();
@@ -3475,7 +3455,7 @@ void HwpReader::makeTable(TxtBox * hbox)
 
 // ----------- cell ---------------- //
     int j = -1, k = -1;
-    for( i = 0 ; i < (int)tbl->cells.size(); i++ )
+    for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
     {
 	std::list<TCell*>::iterator it = tbl->cells.begin();
 
@@ -3696,7 +3676,7 @@ void HwpReader::makeFormula(TxtBox * hbox)
         {
             if (!cshape)
                 cshape = pPar->GetCharShape(n);
-            if (l >= sizeof(mybuf)-1)
+            if (l >= sizeof(mybuf)-7)
                 break;
                 res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
                 for( int j = 0 ; j < res; j++ ){
@@ -3712,7 +3692,7 @@ void HwpReader::makeFormula(TxtBox * hbox)
                     }
                 }
         }
-        if (l >= sizeof(mybuf)-1)
+        if (l >= sizeof(mybuf)-7)
             break;
         mybuf[l++] = '\n';
         pPar = pPar->Next();
@@ -3739,32 +3719,35 @@ void HwpReader::makeHyperText(TxtBox * hbox)
      if( !hypert ) return;
 
     if( strlen((char *)hypert->filename) > 0 ){
-              char tmp[256];
-              char tmp2[256];
-              int nSize = hstr2ksstr(hypert->bookmark, tmp);
+              ::std::string const tmp = hstr2ksstr(hypert->bookmark);
+              ::std::string const tmp2 = hstr2ksstr(kstr2hstr(
 #ifdef _WIN32
-              int nSize2 = hstr2ksstr(kstr2hstr((uchar *) urltowin((char *)hypert->filename, buf), sbuf), tmp2);
+                  (uchar *) urltowin((char *)hypert->filename).c_str()).c_str());
 #else
-              int nSize2 = hstr2ksstr(kstr2hstr( (uchar *)urltounix((char *)hypert->filename, buf), sbuf), tmp2);
+                  (uchar *) urltounix((char *)hypert->filename).c_str()).c_str());
 #endif
           padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
-          if( strlen(tmp) > 0 && strcmp( tmp, "[HTML]") ){
-              sprintf( buf, "%s#%s",tmp2, tmp);
-              padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize2 + nSize+1, RTL_TEXTENCODING_EUC_KR));
+          if (tmp.size() > 0 && strcmp(tmp.c_str(), "[HTML]")) {
+              ::std::string tmp3(tmp2);
+              tmp3.push_back('#');
+              tmp3.append(tmp);
+              padd(ascii("xlink:href"), sXML_CDATA,
+                  OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR));
           }
           else{
-              sprintf( buf, "%s",tmp2);
-              padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize2, RTL_TEXTENCODING_EUC_KR));
+              padd(ascii("xlink:href"), sXML_CDATA,
+                  OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR));
 
           }
      }
     else
     {
-        char tmp[256];
         padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
-        int nSize = hstr2ksstr(hypert->bookmark, tmp);
-        sprintf( buf, "#%s", tmp);
-        padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize+1, RTL_TEXTENCODING_EUC_KR));
+        ::std::string tmp;
+        tmp.push_back('#');
+        tmp.append(hstr2ksstr(hypert->bookmark));
+        padd(ascii("xlink:href"), sXML_CDATA,
+                OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR));
     }
     rstartEl(ascii("draw:a"), rList);
     pList->clear();
@@ -3837,16 +3820,16 @@ void HwpReader::makePicture(Picture * hbox)
                 padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
 #ifdef _WIN32
                 if( hbox->follow[4] != 0 )
-                    padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4, sbuf), gstr)));
+                    padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4).c_str())));
                 else
-                    padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5, sbuf), gstr)));
+                    padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5).c_str())));
 #else
                 if( hbox->follow[4] != 0 )
                     padd(ascii("xlink:href"), sXML_CDATA,
-                        (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4), buf), sbuf), gstr)));
+                        (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4)).c_str()).c_str())));
                 else
                     padd(ascii("xlink:href"), sXML_CDATA,
-                        (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5), buf), sbuf), gstr)));
+                        (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5)).c_str()).c_str())));
 #endif
                 rstartEl(ascii("draw:a"), rList);
                 pList->clear();
@@ -3898,10 +3881,10 @@ void HwpReader::makePicture(Picture * hbox)
             if ( hbox->pictype == PICTYPE_FILE ){
 #ifdef _WIN32
                 sprintf(buf, "file:///%s", hbox->picinfo.picun.path );
-                padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf, sbuf), gstr)));
+                padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf).c_str())));
 #else
                 padd(ascii("xlink:href"), sXML_CDATA,
-                    (hconv(kstr2hstr((uchar *) urltounix( hbox->picinfo.picun.path, buf), sbuf), gstr)));
+                    (hconv(kstr2hstr((uchar *) urltounix(hbox->picinfo.picun.path).c_str()).c_str())));
 #endif
                 padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
                 padd(ascii("xlink:show"), sXML_CDATA, ascii("embed"));
@@ -4366,7 +4349,10 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox)
 
                     OUString oustr;
 
-                    if (drawobj->u.freeform.npt > 2){
+                    if ((drawobj->u.freeform.npt > 2) &&
+                        (static_cast<size_t>(drawobj->u.freeform.npt) <
+                         (::std::numeric_limits<int>::max() / sizeof(double))))
+                    {
                               int n, i;
                               n = drawobj->u.freeform.npt;
 
@@ -4605,7 +4591,8 @@ void HwpReader::makeLine(Line *   )
  */
 void HwpReader::makeHidden(Hidden * hbox)
 {
-    int l = 0, res;
+    hchar_string str;
+    int res;
      hchar dest[3];
 
     padd(ascii("text:condition"), sXML_CDATA, ascii(""));
@@ -4621,11 +4608,13 @@ void HwpReader::makeHidden(Hidden * hbox)
         {
               res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
               for( int j = 0 ; j < res ; j++ )
-                    gstr[l++] = dest[j];
+              {
+                    str.push_back(dest[j]);
+              }
         }
         para = para->Next();
     }
-    makeChars(gstr, l);
+    makeChars(str);
     rendEl(ascii("text:hidden-text"));
 }
 
@@ -4770,8 +4759,8 @@ void HwpReader::makeShowPageNum()
  */
 void HwpReader::makeMailMerge(MailMerge * hbox)
 {
-    hbox->GetString(sbuf, 255);
-    rchars((hconv(sbuf, gstr)));
+    hchar_string const boxstr = hbox->GetString();
+    rchars((hconv(boxstr.c_str())));
 }
 
 
@@ -4796,7 +4785,7 @@ void HwpReader::makeIndexMark(IndexMark *  )      /*hbox */
 void HwpReader::makeOutline(Outline * hbox)
 {
     if( hbox->kind == 1 )
-         rchars(OUString(hbox->GetUnicode(sbuf, 255)));
+        rchars(OUString(hbox->GetUnicode().c_str()));
 }
 
 
diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx
index bcf4300..e5cefc5 100644
--- a/hwpfilter/source/hwpreader.hxx
+++ b/hwpfilter/source/hwpreader.hxx
@@ -130,10 +130,10 @@ private:
     void make_text_p3(HWPPara *para, sal_Bool bParaStart = sal_False);
 
     /* -------- rDocument->characters(x) --------- */
-    void makeChars(hchar *, int);
+    void makeChars(hchar_string & rStr);
 
     /* -------- Special Char Parsing --------- */
-    void makeFieldCode(FieldCode *hbox);        //6
+    void makeFieldCode(hchar_string & rStr, FieldCode *hbox); //6
     void makeBookmark(Bookmark *hbox);      //6
     void makeDateFormat(DateCode *hbox);    //7
     void makeDateCode(DateCode *hbox);      //8
diff --git a/hwpfilter/source/mapping.h b/hwpfilter/source/mapping.h
index f59e644..e7f6c32 100644
--- a/hwpfilter/source/mapping.h
+++ b/hwpfilter/source/mapping.h
@@ -24,7 +24,8 @@
 #include <stdio.h>
 #include <sal/macros.h>
 
-typedef unsigned short hchar;
+#include <hwplib.h>
+
 
 struct FormulaEntry{
      const char *tex;
@@ -360,30 +361,31 @@ const struct FormulaEntry FormulaMapTab[] = {
 };
 
 #ifndef DEBUG
-hchar *getMathMLEntity(const char *tex, hchar *buf)
+hchar_string getMathMLEntity(const char *tex)
 {
-     static int tabSize = SAL_N_ELEMENTS( FormulaMapTab );
-     int i, len;
+     static size_t tabSize = sizeof(FormulaMapTab) / sizeof(FormulaMapTab[0]);
 
-     for( i = 0 ; i < tabSize ; i++ ){
+     hchar_string buf;
+     for (size_t i = 0 ; i < tabSize ; i++) {
           if( !strcmp(tex, FormulaMapTab[i].tex ) ) {
-                buf[0] = FormulaMapTab[i].ucs;
-                buf[1] = '\0';
+                buf.push_back(FormulaMapTab[i].ucs);
                 return buf;
           }
      }
-     len = strlen(tex);
 
-     for( i = 0 ; i < len ; i++ )
-          buf[i] = tex[i];
-     buf[len] = 0;
+     size_t const len = strlen(tex);
+     for (size_t i = 0 ; i < len ; i++)
+     {
+         buf.push_back(tex[i]);
+     }
      return buf;
 }
 
 #else
-char *getMathMLEntity(const char *tex, char *buf)
+::std::string getMathMLEntity(const char *tex)
 {
-     strcpy(buf,tex);
+     ::std::string buf;
+     buf.append(tex);
      return buf;
 }
 #endif
commit e5762c8488e233ac7de394d631202d452b1c92a4
Author: Michael Stahl <mst at openoffice.org>
Date:   Tue Jul 24 11:22:39 2012 +0200

    mhu24: add comphelper::newArray_{null,ex} helpers
    
    Change-Id: I5cba60c8a14fc8d0adc0c4c5273aabbdd9830f91

diff --git a/comphelper/Package_inc.mk b/comphelper/Package_inc.mk
index c9796c5..195a5c9 100644
--- a/comphelper/Package_inc.mk
+++ b/comphelper/Package_inc.mk
@@ -123,5 +123,6 @@ $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/processfactory.h
 $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/sequenceashashmap.hxx,comphelper/sequenceashashmap.hxx))
 $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/configuration.hxx,comphelper/configuration.hxx))
 $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/configurationhelper.hxx,comphelper/configurationhelper.hxx))
+$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/newarray.hxx,comphelper/newarray.hxx))
 
 # vim: set noet sw=4 ts=4:
diff --git a/comphelper/inc/comphelper/newarray.hxx b/comphelper/inc/comphelper/newarray.hxx
new file mode 100644
index 0000000..d7ce756
--- /dev/null
+++ b/comphelper/inc/comphelper/newarray.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef COMPHELPER_NEW_ARRAY_HXX
+#define COMPHELPER_NEW_ARRAY_HXX
+
+#include <limits>
+#include <new>
+#include <stddef.h>
+
+namespace comphelper {
+
+template<typename T> T *
+newArray_null(size_t const n) throw()
+{
+    if ((::std::numeric_limits<size_t>::max() / sizeof(T)) <= n) {
+        return 0;
+    }
+    return new (::std::nothrow) T[n];
+}
+
+template<typename T> T *
+newArray_ex(size_t const n)
+{
+    if ((::std::numeric_limits<size_t>::max() / sizeof(T)) <= n) {
+        throw ::std::bad_alloc();
+    }
+    return new T[n];
+}
+
+} // namespace comphelper
+
+#endif // COMPHELPER_NEW_ARRAY_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 84052694960b34371e9e82ce3c8fbcdc3d1ab9d8
Author: Michael Stahl <mst at openoffice.org>
Date:   Tue Jul 24 11:21:12 2012 +0200

    better page descriptor handling in RTF
    
    Change-Id: I88384cf3a059c9988499b63512aafd411cf0dd9a

diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx
index 8b53d6d..c210149 100644
--- a/sw/source/filter/rtf/swparrtf.cxx
+++ b/sw/source/filter/rtf/swparrtf.cxx
@@ -3233,6 +3233,7 @@ void SwRTFParser::ReadPageDescTbl()
 
     sal_uInt16 nCols = USHRT_MAX, nColSpace = USHRT_MAX, nAktCol = 0;
     std::vector<sal_uInt16> aColumns;
+    ::std::map< const SwPageDesc*, sal_uInt16 > aFollowMap; //store index of following page descriptors
 
     while( nNumOpenBrakets && IsParserWorking() )
     {
@@ -3295,10 +3296,9 @@ void SwRTFParser::ReadPageDescTbl()
             break;
 
         case RTF_PGDSCNXT:
-            // setze erstmal nur die Nummer als Follow. Am Ende der
-            // Tabelle wird diese entsprechend korrigiert !!
+            // store index of follow in map; will be fixed up later
             if( nTokenValue )
-                pPg->SetFollow( (const SwPageDesc*)nTokenValue );
+                aFollowMap.insert( ::std::pair<const SwPageDesc*, sal_uInt16>( pPg, nTokenValue ));
             else
                 pPg->SetFollow( &pDoc->GetPageDesc( 0 ) );
             break;
@@ -3466,9 +3466,13 @@ void SwRTFParser::ReadPageDescTbl()
     for( nPos = 0; nPos < pDoc->GetPageDescCnt(); ++nPos )
     {
         SwPageDesc* pPgDsc = &pDoc->GetPageDesc( nPos );
-        if( (sal_uInt16)(long)pPgDsc->GetFollow() < pDoc->GetPageDescCnt() )
-            pPgDsc->SetFollow(& pDoc->GetPageDesc((sal_uInt16)(long)
-                                            pPgDsc->GetFollow()));
+        std::map< const SwPageDesc*, sal_uInt16 >::const_iterator aIter =
+            aFollowMap.find( pPgDsc );
+        if (aIter != aFollowMap.end())
+        {
+            if ((*aIter).second < pDoc->GetPageDescCnt())
+                pPgDsc->SetFollow(& pDoc->GetPageDesc((*aIter).second));
+        }
     }
 
     SetChkStyleAttr( bSaveChkStyleAttr );


More information about the Libreoffice-commits mailing list