Changeset 989


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

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

Location:
cpp/frams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/genomanipulation.cpp

    r977 r989  
    285285        if (gc) printf("found converter accepting f1: \"%s\"\n", gc->name);
    286286        SListTempl<GenoConverter*> found;
    287         Geno::getConverters()->findConverters(&found, Geno::UNKNOWN_FORMAT, '0');
     287        Geno::getConverters()->findConverters(&found, Geno::FORMAT_UNKNOWN, '0');
    288288        printf("found %d converter(s) producing f0\n", found.size());
    289289}
  • 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
  • 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.