]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for Solaris realloc() which moves the memory block even when the block size is...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 12 Oct 2001 17:29:19 +0000 (17:29 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 12 Oct 2001 17:29:19 +0000 (17:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11958 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 7f856761a9dd1bff0ed0846547eac3cdcf5ab54c..938d0010dca8e1a1de0b88325d34eda859a7f2e2 100644 (file)
@@ -497,18 +497,21 @@ void wxString::Shrink()
 {
   wxStringData *pData = GetStringData();
 
-  // this variable is unused in release build, so avoid the compiler warning
-  // by just not declaring it
-#ifdef __WXDEBUG__
-  void *p =
-#endif
-  realloc(pData, sizeof(wxStringData) + (pData->nDataLength + 1)*sizeof(wxChar));
+  size_t nLen = pData->nDataLength;
+  void *p = realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
 
-  // we rely on a reasonable realloc() implementation here - so far I haven't
-  // seen any which wouldn't behave like this
+  wxASSERT_MSG( p != NULL, _T("can't free memory?") );
+
+  if ( p != pData )
+  {
+      // contrary to what one might believe, some realloc() implementation do
+      // move the memory block even when its size is reduced
+      pData = (wxStringData *)p;
+
+      m_pchData = pData->data();
+  }
 
-  wxASSERT( p != NULL );  // can't free memory?
-  wxASSERT( p == pData ); // we're decrementing the size - block shouldn't move!
+  pData->nAllocLength = nLen;
 }
 
 // get the pointer to writable buffer of (at least) nLen bytes