fixed wxVsnprintf() to write as much as it can if the output buffer is too short

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2007-06-29 19:28:54 +00:00
parent 4d62edfb07
commit ec873c943d

View File

@ -552,7 +552,7 @@ namespace
{
#if !wxUSE_UTF8_LOCALE_ONLY
int wxInternalConvertStringToBuf(const wxString& s, char *out, size_t outsize)
int ConvertStringToBuf(const wxString& s, char *out, size_t outsize)
{
const wxWX2WCbuf buf = s.wc_str();
@ -565,13 +565,19 @@ int wxInternalConvertStringToBuf(const wxString& s, char *out, size_t outsize)
#endif // !wxUSE_UTF8_LOCALE_ONLY
#if wxUSE_UNICODE_UTF8
int wxInternalConvertStringToBuf(const wxString& s, wchar_t *out, size_t outsize)
int ConvertStringToBuf(const wxString& s, wchar_t *out, size_t outsize)
{
const wxWX2WCbuf buf(s.wc_str());
size_t len = wxWcslen(buf);
size_t len = s.length(); // same as buf length for wchar_t*
if ( outsize > len )
{
memcpy(out, buf, (len+1) * sizeof(wchar_t));
// else: not enough space
}
else // not enough space
{
memcpy(out, buf, (outsize-1) * sizeof(wchar_t));
out[outsize-1] = 0;
}
return len;
}
#endif // wxUSE_UNICODE_UTF8
@ -585,7 +591,7 @@ static size_t PrintfViaString(T *out, size_t outsize,
wxString s;
s.PrintfV(format, argptr);
return wxInternalConvertStringToBuf(s, out, outsize);
return ConvertStringToBuf(s, out, outsize);
}
#endif // wxUSE_UNICODE