]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix bug in wxMBConv_cf::FromWChar() in OS X.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 Mar 2010 22:39:39 +0000 (22:39 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 Mar 2010 22:39:39 +0000 (22:39 +0000)
Apparently CFStringGetBytes() doesn't always behave as expected, work around
this by checking that the returned buffer size is not greater than the size we
passed in.

Closes #11859.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63772 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/core/strconv_cf.cpp

index aba24024113a9daba1f4ee588dcd3fac58031de6..c77825c23ac77f56008b2239b8ba84e57901234e 100644 (file)
@@ -212,13 +212,15 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_cf(wxFontEncoding encoding)
                 m_encoding,
                 0, // FAIL on unconvertible characters
                 false, // not an external representation
                 m_encoding,
                 0, // FAIL on unconvertible characters
                 false, // not an external representation
-                // if dstSize is 0 then pass NULL to get required length in usedBufLen
-                (dstSize != 0)?(UInt8*)dst:NULL,
+                (UInt8*)dst,
                 dstSize,
                 &usedBufLen
             );
 
                 dstSize,
                 &usedBufLen
             );
 
-        if(charsConverted < CFStringGetLength(theString) )
+        // when dst is non-NULL, we check usedBufLen against dstSize as
+        // CFStringGetBytes sometimes treats dst as being NULL when dstSize==0
+        if( (charsConverted < CFStringGetLength(theString)) ||
+                (dst && (size_t) usedBufLen > dstSize) )
             return wxCONV_FAILED;
 
         return usedBufLen;
             return wxCONV_FAILED;
 
         return usedBufLen;