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

Re: [reSIProcate] String corruption fix


Thanks for the fix -- I modified the code a bit more. Instead of reallocating
inline, I called resize for the Share case. resize correctly adds the 1 for
null terminating.

Note that new char[] is called in only Data constructor and resize.
Similarly, delete[] is called in only ~Data and resize.

david


Quoting Christian_Gavin@xxxxxxxxxxxx:

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

_______________________________________________
resiprocate-devel mailing list
resiprocate-devel@xxxxxxxxxxxxxxxxxxx
https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel