- UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ;
- converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ;
+ wxASSERT_MSG( byteBufferLen != wxCONV_FAILED,
+ wxT("Conversion to UTF-16 unexpectedly failed") );
+ UniChar *unibuf = (UniChar*)malloc( byteBufferLen + 2 ) ; // 2 for NUL in UTF-16
+ converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen + 2 ) ;