diff options
author | Michael Stahl <mst@openoffice.org> | 2012-07-24 11:36:17 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-07-24 11:37:41 +0200 |
commit | 5a243f140975167aa5c42c95b30edb1cdb1ea639 (patch) | |
tree | d0f3d0512c06692c7e818cf20288e2514e4c736b /hwpfilter/source/hbox.h | |
parent | e5762c8488e233ac7de394d631202d452b1c92a4 (diff) |
hwpfilter: improve text import and error handling
Change-Id: Ib74b96200c9d57f55fc0d32b638601c64e7eb6fe
Diffstat (limited to 'hwpfilter/source/hbox.h')
-rw-r--r-- | hwpfilter/source/hbox.h | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h index 36e1361f9b00..4fe659894e87 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) */ |