fix for Solaris realloc() which moves the memory block even when the block size is reduced

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11958 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-10-12 17:29:19 +00:00
parent 8b530febd8
commit 337a001037

View File

@@ -497,18 +497,21 @@ void wxString::Shrink()
{ {
wxStringData *pData = GetStringData(); wxStringData *pData = GetStringData();
// this variable is unused in release build, so avoid the compiler warning size_t nLen = pData->nDataLength;
// by just not declaring it void *p = realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
#ifdef __WXDEBUG__
void *p =
#endif
realloc(pData, sizeof(wxStringData) + (pData->nDataLength + 1)*sizeof(wxChar));
// we rely on a reasonable realloc() implementation here - so far I haven't wxASSERT_MSG( p != NULL, _T("can't free memory?") );
// seen any which wouldn't behave like this
wxASSERT( p != NULL ); // can't free memory? if ( p != pData )
wxASSERT( p == pData ); // we're decrementing the size - block shouldn't move! {
// 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();
}
pData->nAllocLength = nLen;
} }
// get the pointer to writable buffer of (at least) nLen bytes // get the pointer to writable buffer of (at least) nLen bytes