X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/50dee7e0ebbe05574116dce391596ddc55d644be..d9963bbb21b16e7c869eed057029684eff0fa520:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 4c61c07ee8..c43bde8e7d 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -245,7 +245,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) size_t nLen; if ( psz ) { - // calculate the needed size ourselves or use a provide one + // calculate the needed size ourselves or use the provided one nLen = nLength == wxSTRING_MAXLEN ? conv.MB2WC(NULL, psz, 0) : nLength; } else @@ -263,10 +263,14 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) } else { - // MB2WC wants the buffer size, not the string length - if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 ) + // MB2WC wants the buffer size, not the string length hence +1 + nLen = conv.MB2WC(m_pchData, psz, nLen + 1); + + if ( nLen != (size_t)-1 ) { - // initialized ok + // initialized ok, set the real length as nLength specified by + // the caller could be greater than the real string length + GetStringData()->nDataLength = nLen; m_pchData[nLen] = 0; return; } @@ -287,7 +291,7 @@ wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength) size_t nLen; if ( pwz ) { - // calculate the needed size ourselves or use a provide one + // calculate the needed size ourselves or use the provided one nLen = nLength == wxSTRING_MAXLEN ? conv.WC2MB(NULL, pwz, 0) : nLength; } else @@ -1755,10 +1759,10 @@ wxString& wxString::replace(size_t nStart, size_t nLen, // ArrayString // ============================================================================ -#if !wxUSE_STL - #include "wx/arrstr.h" +#if !wxUSE_STL + // size increment = min(50% of current size, ARRAY_MAXSIZE_INCREMENT) #define ARRAY_MAXSIZE_INCREMENT 4096