Commit 0aa1af21 authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Disallow format 0 in SetClipboardData.

parent 614e52e8
...@@ -400,6 +400,12 @@ HANDLE WINAPI SetClipboardData(UINT wFormat, HANDLE hData) ...@@ -400,6 +400,12 @@ HANDLE WINAPI SetClipboardData(UINT wFormat, HANDLE hData)
TRACE("(%04X, %p) !\n", wFormat, hData); TRACE("(%04X, %p) !\n", wFormat, hData);
if (!wFormat)
{
SetLastError( ERROR_CLIPBOARD_NOT_OPEN );
return 0;
}
/* If it's not owned, data can only be set if the format isn't /* If it's not owned, data can only be set if the format isn't
available and its rendering is not delayed */ available and its rendering is not delayed */
if (!CLIPBOARD_GetClipboardInfo(&cbinfo) || if (!CLIPBOARD_GetClipboardInfo(&cbinfo) ||
......
...@@ -111,6 +111,7 @@ static void test_RegisterClipboardFormatA(void) ...@@ -111,6 +111,7 @@ static void test_RegisterClipboardFormatA(void)
char buf[256]; char buf[256];
int len; int len;
BOOL ret; BOOL ret;
HANDLE handle;
format_id = RegisterClipboardFormatA("my_cool_clipboard_format"); format_id = RegisterClipboardFormatA("my_cool_clipboard_format");
ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id); ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id);
...@@ -165,6 +166,25 @@ todo_wine ...@@ -165,6 +166,25 @@ todo_wine
ret = OpenClipboard(0); ret = OpenClipboard(0);
ok( ret, "OpenClipboard error %d\n", GetLastError()); ok( ret, "OpenClipboard error %d\n", GetLastError());
/* try some invalid/unregistered formats */
SetLastError( 0xdeadbeef );
handle = SetClipboardData( 0, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
ok( !handle, "SetClipboardData succeeded\n" );
ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN, "wrong error %u\n", GetLastError());
handle = SetClipboardData( 0x1234, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
handle = SetClipboardData( 0x123456, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
handle = SetClipboardData( 0xffff8765, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
ok( IsClipboardFormatAvailable( 0x1234 ), "format missing\n" );
ok( IsClipboardFormatAvailable( 0x123456 ), "format missing\n" );
ok( IsClipboardFormatAvailable( 0xffff8765 ), "format missing\n" );
ok( !IsClipboardFormatAvailable( 0 ), "format available\n" );
ok( !IsClipboardFormatAvailable( 0x3456 ), "format available\n" );
ok( !IsClipboardFormatAvailable( 0x8765 ), "format available\n" );
trace("# of formats available: %d\n", CountClipboardFormats()); trace("# of formats available: %d\n", CountClipboardFormats());
format_id = 0; format_id = 0;
......
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