X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c08d805c5a3fb6495509fb2e25af4e398ca434cc..dc683654a1af7f02ee87623a713a7147bcb6dd84:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index d448b4b306..aa150ea4af 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -312,13 +312,15 @@ bool wxStringBase::AllocBeforeWrite(size_t nLen) pData->nAllocLength = nLen; m_pchData = pData->data(); } - - // now we have enough space, just update the string length - pData->nDataLength = nLen; } wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner + // it doesn't really matter what the string length is as it's going to be + // overwritten later but, for extra safety, set it to 0 for now as we may + // have some junk in m_pchData + GetStringData()->nDataLength = 0; + return true; } @@ -380,7 +382,9 @@ bool wxStringBase::Alloc(size_t nLen) // allocation failure handled by caller return false; } - memcpy(m_pchData, pData->data(), nOldLen*sizeof(wxChar)); + // +1 to copy the terminator, too + memcpy(m_pchData, pData->data(), (nOldLen+1)*sizeof(wxChar)); + GetStringData()->nDataLength = nOldLen; } else { nLen += EXTRA_ALLOC;