]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
include version information in DLLs
[wxWidgets.git] / src / common / string.cpp
index b9e30160aa606bdb8ac09986cc96d61489c8b57e..aa150ea4afca0dbf7c5455cc5161142721e50904 100644 (file)
@@ -312,13 +312,15 @@ bool wxStringBase::AllocBeforeWrite(size_t nLen)
       pData->nAllocLength = nLen;
       m_pchData = pData->data();
     }
       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
 
   }
 
   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;
 }
 
   return true;
 }
 
@@ -326,7 +328,7 @@ wxStringBase& wxStringBase::append(size_t n, wxChar ch)
 {
     size_type len = length();
 
 {
     size_type len = length();
 
-    if ( !CopyBeforeWrite() || !Alloc(len + n) ) {
+    if ( !Alloc(len + n) || !CopyBeforeWrite() ) {
       wxFAIL_MSG( _T("out of memory in wxStringBase::append") );
     }
     GetStringData()->nDataLength = len + n;
       wxFAIL_MSG( _T("out of memory in wxStringBase::append") );
     }
     GetStringData()->nDataLength = len + n;
@@ -380,7 +382,9 @@ bool wxStringBase::Alloc(size_t nLen)
         // allocation failure handled by caller
         return false;
       }
         // 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;
     }
     else {
       nLen += EXTRA_ALLOC;
@@ -445,7 +449,7 @@ wxStringBase& wxStringBase::insert(size_t nPos, const wxChar *sz, size_t n)
   if ( n == npos ) n = wxStrlen(sz);
   if ( n == 0 ) return *this;
 
   if ( n == npos ) n = wxStrlen(sz);
   if ( n == 0 ) return *this;
 
-  if ( !CopyBeforeWrite() || !Alloc(length() + n) ) {
+  if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
     wxFAIL_MSG( _T("out of memory in wxStringBase::insert") );
   }
 
     wxFAIL_MSG( _T("out of memory in wxStringBase::insert") );
   }
 
@@ -1225,7 +1229,7 @@ wxString operator+(const wxString& str, const wxChar *psz)
   if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) {
     wxFAIL_MSG( _T("out of memory in wxString::operator+") );
   }
   if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) {
     wxFAIL_MSG( _T("out of memory in wxString::operator+") );
   }
-  s = str;
+  s += str;
   s += psz;
 
   return s;
   s += psz;
 
   return s;