]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
fix when bitmap is not valid
[wxWidgets.git] / src / common / strconv.cpp
index f1d4c56ea2c2567c793fa0e3c7131101ad544b68..cf96614eef8034e73e0f9cce3ec9c62508e2a28d 100644 (file)
@@ -67,7 +67,7 @@ public:
     virtual void OnExit()
     {
 #if wxUSE_WCHAR_T
-        wxConvLocal.Clear();
+         wxConvLocal.Clear();
 #endif
     }
 
@@ -195,7 +195,6 @@ size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
     {
         for (size_t i = 0; i < strlen( psz )+1; i++)
             buf[i] = (wchar_t) psz[i];
-        // printf( "libc %s\n", buf );
         return strlen( psz );
     }
     else
@@ -214,7 +213,6 @@ size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
     {
         for (size_t i = 0; i < wxStrlen( psz )+1; i++)
             buf[i] = (char) psz[i];
-        // printf( "libc %s\n", buf );
         return wxStrlen( psz );
     }
     else
@@ -250,7 +248,6 @@ const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
             return wxCharBuffer((char *) NULL);
         wxCharBuffer buf(nLen);                      // this allocates nLen+1
         WC2MB((char *)(const char *) buf, psz, nLen+1);
-        // printf( "str %s\n", (const char*) buf );
         return buf;
     }
     else
@@ -661,6 +658,12 @@ size_t IC_CharSet::MB2WC(wchar_t *buf, const char *psz, size_t n)
             // convert to native endianness
             WC_BSWAP(buf /* _not_ bufPtr */, res)
         }
+        
+        // NB: iconv was given only strlen(psz) characters on input, and so
+        //     it couldn't convert the trailing zero. Let's do it ourselves
+        //     if there's some room left for it in the output buffer.
+        if (res < n)
+            buf[res] = 0;
     }
     else
     {
@@ -720,6 +723,12 @@ size_t IC_CharSet::WC2MB(char *buf, const wchar_t *psz, size_t n)
         cres = iconv( w2m, ICONV_CHAR_CAST(&psz), &inbuf, &buf, &outbuf );
 
         res = n-outbuf;
+        
+        // NB: iconv was given only wcslen(psz) characters on input, and so
+        //     it couldn't convert the trailing zero. Let's do it ourselves
+        //     if there's some room left for it in the output buffer.
+        if (res < n)
+            buf[0] = 0;
     }
     else
     {