Correctly convert wxPrintf() to a buffer even when it doesn't fit.
ConvertStringToBuf() helper function was defined incorrectly for converting wxString to a char* buffer as it didn't fill the buffer at all if the string didn't fit into it entirely instead of putting as much of the string into it as possible as was already done for the conversion to wchar_t* buffer. This broke wxSprintf()-related functions in when the ASCII output buffer was not big enough as it was not filled at all. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65691 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
37513b6715
commit
0e555c213d
@ -586,13 +586,20 @@ namespace
|
||||
#if !wxUSE_UTF8_LOCALE_ONLY
|
||||
int ConvertStringToBuf(const wxString& s, char *out, size_t outsize)
|
||||
{
|
||||
const wxWX2WCbuf buf = s.wc_str();
|
||||
const wxCharBuffer buf(s.mb_str());
|
||||
|
||||
size_t len = wxConvLibc.FromWChar(out, outsize, buf);
|
||||
if ( len != wxCONV_FAILED )
|
||||
return len-1;
|
||||
else
|
||||
return wxConvLibc.FromWChar(NULL, 0, buf);
|
||||
const size_t len = buf.length();
|
||||
if ( outsize > len )
|
||||
{
|
||||
memcpy(out, buf, (len+1) * sizeof(char));
|
||||
}
|
||||
else // not enough space
|
||||
{
|
||||
memcpy(out, buf, (outsize-1) * sizeof(char));
|
||||
out[outsize-1] = '\0';
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif // !wxUSE_UTF8_LOCALE_ONLY
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user