user32: Disallow format 0 in SetClipboardData.

This commit is contained in:
Alexandre Julliard 2015-06-05 17:30:28 +09:00
parent 614e52e897
commit 0aa1af219f
2 changed files with 26 additions and 0 deletions

View File

@ -400,6 +400,12 @@ HANDLE WINAPI SetClipboardData(UINT wFormat, HANDLE 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
available and its rendering is not delayed */
if (!CLIPBOARD_GetClipboardInfo(&cbinfo) ||

View File

@ -111,6 +111,7 @@ static void test_RegisterClipboardFormatA(void)
char buf[256];
int len;
BOOL ret;
HANDLE handle;
format_id = RegisterClipboardFormatA("my_cool_clipboard_format");
ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id);
@ -165,6 +166,25 @@ todo_wine
ret = OpenClipboard(0);
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());
format_id = 0;