From 11ed408c51e4af892f9b92c541c87a1bf973532d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 10 Jul 2003 12:13:49 +0000 Subject: [PATCH] set string length properly in wxString(p, conv, len) ctor (patch 755593) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@21859 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/string.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/string.cpp b/src/common/string.cpp index 3465875613..c05df8f997 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -263,10 +263,14 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) return; } - // 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; }