Commit a9dcbfe2 authored by Dimitri van Heesch's avatar Dimitri van Heesch

Fixed refcounting bug in new string implementation

parent 9323ae47
...@@ -498,19 +498,22 @@ public: ...@@ -498,19 +498,22 @@ public:
} }
StringRep &operator=(const StringRep &s) StringRep &operator=(const StringRep &s)
{ {
if (!u.s.isShort) if (&s!=this)
{
u.l.d->dispose();
}
if (s.u.s.isShort) // copy by value
{
u.s = s.u.s;
}
else // copy by reference
{ {
u.l.isShort=FALSE; if (!u.s.isShort)
u.l.d = s.u.l.d; {
u.l.d->refCount++; u.l.d->dispose();
}
if (s.u.s.isShort) // copy by value
{
u.s = s.u.s;
}
else // copy by reference
{
u.l.isShort=FALSE;
u.l.d = s.u.l.d;
u.l.d->refCount++;
}
} }
return *this; return *this;
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment