From 6986b8e609568cc5acb37678b81f68e0117204b5 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Tue, 26 Mar 2019 00:18:54 +0100 Subject: [PATCH] fix memory corruption in clipboard copying was copying WCHAR size instead of char (wtf) --- src/platform_w32_common/Clipboard.cpp | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/platform_w32_common/Clipboard.cpp b/src/platform_w32_common/Clipboard.cpp index e40a14f8..e5bf1ef2 100644 --- a/src/platform_w32_common/Clipboard.cpp +++ b/src/platform_w32_common/Clipboard.cpp @@ -5,19 +5,19 @@ namespace Clipboard void Copy( const char * data, int len ) { HWND hWnd = GetForegroundWindow(); - if (!::OpenClipboard( hWnd )) + if ( !::OpenClipboard( hWnd ) ) return; EmptyClipboard(); - HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE,(len + 1) * sizeof(WCHAR)); - WCHAR * pMem = (WCHAR*)GlobalLock(h); + HGLOBAL h = GlobalAlloc( GMEM_MOVEABLE, ( len + 1 ) * sizeof( char ) ); + WCHAR * pMem = (WCHAR*) GlobalLock( h ); - ZeroMemory( pMem, (len + 1) * sizeof(WCHAR) ); - CopyMemory( pMem, data, (len + 1) * sizeof(WCHAR) ); + ZeroMemory( pMem, ( len + 1 ) * sizeof( char ) ); + CopyMemory( pMem, data, ( len + 1 ) * sizeof( char ) ); - GlobalUnlock(h); - SetClipboardData(CF_TEXT,h); + GlobalUnlock( h ); + SetClipboardData( CF_TEXT, h ); CloseClipboard(); } @@ -25,12 +25,12 @@ namespace Clipboard int GetContentsLength() { HWND hWnd = GetForegroundWindow(); - if (!::OpenClipboard( hWnd )) + if ( !::OpenClipboard( hWnd ) ) return 0; - HANDLE hData = GetClipboardData(CF_TEXT); - const char * buffer = (const char*)GlobalLock( hData ); - int n = strlen(buffer); + HANDLE hData = GetClipboardData( CF_TEXT ); + const char * buffer = (const char*) GlobalLock( hData ); + int n = strlen( buffer ); CloseClipboard(); @@ -40,11 +40,11 @@ namespace Clipboard void GetContents( char * data, int len ) { HWND hWnd = GetForegroundWindow(); - if (!::OpenClipboard( hWnd )) + if ( !::OpenClipboard( hWnd ) ) return; - HANDLE hData = GetClipboardData(CF_TEXT); - const char * buffer = (const char*)GlobalLock( hData ); + HANDLE hData = GetClipboardData( CF_TEXT ); + const char * buffer = (const char*) GlobalLock( hData ); strncpy( data, buffer, len ); CloseClipboard();