From: Vadim Zeitlin Date: Thu, 10 Jul 2003 12:13:49 +0000 (+0000) Subject: set string length properly in wxString(p, conv, len) ctor (patch 755593) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/251a8ce858c489c5955446e97d293cc8c02d6736?ds=inline set string length properly in wxString(p, conv, len) ctor (patch 755593) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21859 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/string.cpp b/src/common/string.cpp index 4c61c07ee8..29d51e71b8 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