]> git.saurik.com Git - wxWidgets.git/commitdiff
don't crash if used in iconv-like fashion
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 18 Aug 2002 17:23:08 +0000 (17:23 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 18 Aug 2002 17:23:08 +0000 (17:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/strconv.cpp

index a7db44b730d07506228f03468ec257e8164289dc..745aef9699543641c12459c51477b53c15cd1221 100644 (file)
@@ -662,8 +662,11 @@ size_t IC_CharSet::MB2WC(wchar_t *buf, const char *psz, size_t n)
             WC_BSWAP(buf /* _not_ bufPtr */, res)
         }
         
             WC_BSWAP(buf /* _not_ bufPtr */, res)
         }
         
-        // iconv doesn't seem to set the trailing 0
-        buf[res] = 0;
+        // 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
     {
     }
     else
     {
@@ -724,9 +727,11 @@ size_t IC_CharSet::WC2MB(char *buf, const wchar_t *psz, size_t n)
 
         res = n-outbuf;
         
 
         res = n-outbuf;
         
-        // iconv() doesn't set the trailing zero, but moves buf to
-        // that position
-        buf[0] = 0;
+        // 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
     {
     }
     else
     {