< Previous by Date Date Index Next by Date >
  Thread Index Next in Thread >

[reSIProcate] String corruption fix


Hi,

Here is the fix I made locally to data.cxx

Data&
Data::append(const char* str, size_type len)
{
   assert(str);
   if (mCapacity < mSize + len)
   {
      // .dlb. pad for future growth?
      resize(((mSize + len +16)*3)/2, true);
   }
   else
   {
      if (mMine == Share)
      {
         char *oldBuf = mBuf;
         mCapacity = mSize + len;
         mBuf = new char[mSize + len + 1];      // << FIX here: added +1 to
account for extra '\0' !
         memcpy(mBuf, oldBuf, mSize);
         mMine = Take;
      }
   }

   // could conceivably overlap
   memmove(mBuf + mSize, str, len);
   mSize += len;
   mBuf[mSize] = 0;

   return *this;
}

It solved the memory corruption problem when appending strings.

Please consider applying this fix to the subversion repository.

Thanks,
CG