]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
fixes to handling of focus changes for toplevel windows
[wxWidgets.git] / src / common / string.cpp
index 8bb9f91edc6b2f0c8ba95d43ef9a5f451dff5766..7b9f77b28b47918eed64cac21e89ffcf4e75ef1a 100644 (file)
@@ -973,35 +973,36 @@ 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;
+    wxImplStringBuffer buf(res, len);
+    wxStringCharType *dest = buf;
 
-        for ( ;; )
-        {
-            unsigned char c = (unsigned char)*ascii++;
-            wxASSERT_MSG( c < 0x80,
-                          _T("Non-ASCII value passed to FromAscii().") );
+    for ( ;; )
+    {
+        unsigned char c = (unsigned char)*ascii++;
+        wxASSERT_MSG( c < 0x80,
+                      _T("Non-ASCII value passed to FromAscii().") );
 
-            *dest++ = (wchar_t)c;
+        *dest++ = (wchar_t)c;
 
-            if ( c == '\0' )
-                break;
-        }
+        if ( c == '\0' )
+            break;
     }
 
     return res;
 }
 
+wxString wxString::FromAscii(const char *ascii)
+{
+    return FromAscii(ascii, strlen(ascii));
+}
+
 wxString wxString::FromAscii(const char ascii)
 {
     // What do we do with '\0' ?
@@ -1566,6 +1567,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 +1600,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