Ignore:
Timestamp:
07/09/20 00:21:37 (4 years ago)
Author:
Maciej Komosinski
Message:

SString::endWrite()/endAppend() now safe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/sstring.cpp

    r973 r989  
    222222{
    223223        if (newlength < 0) newlength = strlen(buf->txt);
    224         else buf->txt[newlength] = 0;
     224        else
     225        {
     226                if ((newlength >= (buf->size + 1)) || (buf->size == 0))
     227                {
     228                        assert((newlength < (buf->size + 1)) && (buf->size > 0));
     229                        if (buf->size == 0) return;
     230                        newlength = buf->size;
     231                }
     232                buf->txt[newlength] = 0;
     233        }
    225234        buf->used = newlength;
    226235}
     
    228237void SString::endAppend(int newappend)
    229238{
    230         if (newappend < 0) newappend = strlen(buf->txt + appending);
    231         else buf->txt[appending + newappend] = 0;
    232         buf->used = appending + newappend;
     239        if (newappend < 0) endWrite(appending + strlen(buf->txt + appending));
     240        else endWrite(newappend + appending);
    233241}
    234242
Note: See TracChangeset for help on using the changeset viewer.