Commit 6986b8e6 authored by Gargaj's avatar Gargaj
Browse files

fix memory corruption in clipboard copying

was copying WCHAR size instead of char (wtf)
parent 7269a05f
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment