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
This commit is contained in:
@@ -245,7 +245,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
|
|||||||
size_t nLen;
|
size_t nLen;
|
||||||
if ( psz )
|
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;
|
nLen = nLength == wxSTRING_MAXLEN ? conv.MB2WC(NULL, psz, 0) : nLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -263,10 +263,14 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// MB2WC wants the buffer size, not the string length
|
// MB2WC wants the buffer size, not the string length hence +1
|
||||||
if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-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;
|
m_pchData[nLen] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -287,7 +291,7 @@ wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength)
|
|||||||
size_t nLen;
|
size_t nLen;
|
||||||
if ( pwz )
|
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;
|
nLen = nLength == wxSTRING_MAXLEN ? conv.WC2MB(NULL, pwz, 0) : nLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user