X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/52de37c78f31bc03f8b96090932c7ce8c3907d29..e93523680ba3c83cdae75b511214c82f28a2d853:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 8bb9f91edc..87e5613472 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -973,35 +973,35 @@ int wxString::CmpNoCase(const wxString& s) const #endif #endif -wxString wxString::FromAscii(const char *ascii) +wxString wxString::FromAscii(const char *ascii, size_t len) { - if (!ascii) + if (!ascii || len == 0) return wxEmptyString; - size_t len = strlen(ascii); wxString res; - if ( len ) { wxImplStringBuffer buf(res, len); wxStringCharType *dest = buf; - for ( ;; ) + for ( ; len > 0; --len ) { unsigned char c = (unsigned char)*ascii++; wxASSERT_MSG( c < 0x80, _T("Non-ASCII value passed to FromAscii().") ); *dest++ = (wchar_t)c; - - if ( c == '\0' ) - break; } } return res; } +wxString wxString::FromAscii(const char *ascii) +{ + return FromAscii(ascii, wxStrlen(ascii)); +} + wxString wxString::FromAscii(const char ascii) { // What do we do with '\0' ? @@ -1566,6 +1566,11 @@ static int DoStringPrintfV(wxString& str, if ( !buf ) { // out of memory + + // in UTF-8 build, leaving uninitialized junk in the buffer + // could result in invalid non-empty UTF-8 string, so just + // reset the string to empty on failure: + buf[0] = '\0'; return -1; } @@ -1594,6 +1599,7 @@ static int DoStringPrintfV(wxString& str, // we know that our own implementation of wxVsnprintf() returns -1 // only for a format error - thus there's something wrong with // the user's format string + buf[0] = '\0'; return -1; #else // possibly using system version // assume it only returns error if there is not enough space, but