From: Kevin Hock Date: Sun, 17 Jul 2005 03:21:46 +0000 (+0000) Subject: Consider native data format, zero out buffer before use in case it doesn't get filled... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/99b62b5ffc006137f1bee20f6618ed7a0b7871e1 Consider native data format, zero out buffer before use in case it doesn't get filled [ patch 1237326 ] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index 4267942472..1252a067fc 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -96,7 +96,12 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) if ( dataFormat.GetType() == wxDF_TEXT ) ((char*)data)[byteCount] = 0 ; if ( dataFormat.GetType() == wxDF_UNICODETEXT ) - ((wxChar*)data)[byteCount/2] = 0 ; + { + // "data" format is UTF16, so 2 bytes = one character + // wxChar size depends on platform, so just clear last 2 bytes + ((char*)data)[byteCount] = 0; + ((char*)data)[byteCount+1] = 0; + } } else { @@ -244,6 +249,8 @@ bool wxClipboard::AddData( wxDataObject *data ) void* buf = malloc( sz + 1 ) ; if ( buf ) { + // empty the buffer because in some case GetDataHere does not fill buf + memset(buf, 0, sz+1); data->GetDataHere( array[i] , buf ) ; OSType mactype = 0 ; switch ( array[i].GetType() ) @@ -380,6 +387,7 @@ bool wxClipboard::GetData( wxDataObject& data ) switch ( format.GetType() ) { case wxDF_TEXT : + case wxDF_UNICODETEXT: case wxDF_OEMTEXT : case wxDF_BITMAP : case wxDF_METAFILE :