From a2b04536d37e8387724f8b8cd68410dd72c67ce6 Mon Sep 17 00:00:00 2001 From: Tim Kosse Date: Mon, 20 Mar 2017 10:37:01 +0100 Subject: [PATCH] Create empty wxCFStringRef and not null one if conversion fails If the passed string cannot be represented in the target encoding in the wxCFStringRef constructor, create a reference to an empty string instead of a null ref. Most users of wxCFStringRef cannot handle a null wxCFStringRef. Closes #17825. --- src/osx/core/cfstring.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/osx/core/cfstring.cpp b/src/osx/core/cfstring.cpp index c25dc9d8d5..19ac1f8e3a 100644 --- a/src/osx/core/cfstring.cpp +++ b/src/osx/core/cfstring.cpp @@ -630,9 +630,16 @@ wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UN #else #error "unsupported Unicode representation" #endif - - reset( CFStringCreateWithBytes( kCFAllocatorDefault, - (const UInt8*)data, size, cfencoding, false /* no BOM */ ) ); + CFStringref ref = CFStringCreateWithBytes( kCFAllocatorDefault, + (const UInt8*)data, size, cfencoding, false /* no BOM */ ); + if (ref) + { + reset( ref ); + } + else + { + reset( wxCFRetain( CFSTR("") ) ); + } #else // not wxUSE_UNICODE reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , wxMacGetSystemEncFromFontEnc( encoding ) ) );