Skip to content

Commit

Permalink
Handle case where we assign to ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoromisato committed Dec 4, 2018
1 parent 3519e0f commit 1398bbe
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Kernel/CString.cpp
Expand Up @@ -253,14 +253,19 @@ CString &CString::operator= (const CString &pString)
// Overrides the assignment operator

{
DecRefCount();
// First bump up the new string's refcount, in case it happens to be the
// exact same as ours.

m_pStore = pString.m_pStore;
if (pString.m_pStore)
pString.m_pStore->iRefCount++;

// If we've got a storage, bump up the ref count
// Now decrement our own.

if (m_pStore)
m_pStore->iRefCount++;
DecRefCount();

// Take it.

m_pStore = pString.m_pStore;

return *this;
}
Expand Down

0 comments on commit 1398bbe

Please sign in to comment.