[reSIProcate] String corruption fix
david Butcher
david at purplecomm.com
Wed Jul 13 15:41:38 CDT 2005
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 at logitech.com:
> 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 at list.sipfoundry.org
> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
>
More information about the resiprocate-devel
mailing list