Changeset 339


Ignore:
Timestamp:
Apr 1, 2010, 12:41:16 PM (12 years ago)
Author:
dmik
Message:

branches/kmk: Fixed: uniConvertString would return incorrect output buffer size.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/kmk/Lucide/plugins/ludoc/cpconv.cpp

    r337 r339  
    159159    if ( liglen > 0 )  // string contain ligature(s)
    160160    {
    161         unsigned ulen_tmp = ( unilen + liglen + 1 ) * sizeof( UniChar );
     161        size_t ulen_tmp = ( unilen + liglen + 1 ) * sizeof( UniChar );
    162162        char *uni_tmp = new char[ ulen_tmp ];
    163163        uniReplaceLigatures( unibuf, (UniChar *)uni_tmp );
     
    168168    uniConvertSpChars( unibuf );
    169169
    170     size_t blen = ( unilen + 1 ) * 2;
     170    // take the maximum of 4 chars per each unicode char on output
     171    size_t blen = ( unilen + 1 ) * 4;
    171172    char *b = new char[ blen ];
    172173    memset( b, 0, blen );
    173174    char *bsav = b;
     175    size_t blensav = blen;
    174176    tmpuni = unibuf;
    175177    cSubs = 0;
     
    177179    delete unibuf;
    178180
    179     if ( retLen != NULL)
     181    // tailor the buffer size and append 4 zeros as an all-in-one terminator
     182    blen = blensav - blen;
     183    b = new char[ blen + 4 ];
     184    memcpy( b, bsav, blen );
     185    memset( b + blen, 0, 4 );
     186    delete[] bsav;
     187
     188    if ( retLen != NULL )
    180189        *retLen = blen;
    181     return bsav;
     190    return b;
    182191}
    183192
Note: See TracChangeset for help on using the changeset viewer.