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-simple.cpp

    r973 r989  
    7676{
    7777        if (newlength < 0) newlength = strlen(txt);
    78         else txt[newlength] = 0;
     78        else
     79        {
     80                if (newlength >= allocated)
     81                {
     82                        assert(newlength < allocated);
     83                        if (allocated == 0) return;
     84                        newlength = allocated - 1;
     85                }
     86                txt[newlength] = 0;
     87        }
    7988        used = newlength;
    80         assert(used < allocated);
    8189}
    8290
    8391void SString::endAppend(int newappend)
    8492{
    85         if (newappend < 0) newappend = strlen(txt + appending);
    86         else txt[appending + newappend] = 0;
    87         used = appending + newappend;
    88         assert(used < allocated);
     93        if (newappend < 0) endWrite(appending + strlen(txt + appending));
     94        else endWrite(newappend + appending);
    8995}
    9096
Note: See TracChangeset for help on using the changeset viewer.