diff --git a/src/osx/core/strconv_cf.cpp b/src/osx/core/strconv_cf.cpp index aba2402411..c77825c23a 100644 --- a/src/osx/core/strconv_cf.cpp +++ b/src/osx/core/strconv_cf.cpp @@ -212,13 +212,15 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_cf(wxFontEncoding encoding) 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 ); - 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;