From 8b933495fb4b9a874b9f1f3560847739520ba384 Mon Sep 17 00:00:00 2001 From: Aric Stewart Date: Tue, 17 Sep 2013 13:52:23 -0500 Subject: [PATCH] imm32: Fix ImmGetDescription behavior with a null HKL. --- dlls/imm32/imm.c | 3 +++ dlls/imm32/tests/imm32.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c index 59e7ff21bc6..29bf4af95da 100644 --- a/dlls/imm32/imm.c +++ b/dlls/imm32/imm.c @@ -1523,6 +1523,8 @@ UINT WINAPI ImmGetDescriptionA( /* find out how many characters in the unicode buffer */ len = ImmGetDescriptionW( hKL, NULL, 0 ); + if (!len) + return 0; /* allocate a buffer of that size */ buf = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR) ); @@ -1550,6 +1552,7 @@ UINT WINAPI ImmGetDescriptionW(HKL hKL, LPWSTR lpszDescription, UINT uBufLen) FIXME("(%p, %p, %d): semi stub\n", hKL, lpszDescription, uBufLen); + if (!hKL) return 0; if (!uBufLen) return lstrlenW( name ); lstrcpynW( lpszDescription, name, uBufLen ); return lstrlenW( lpszDescription ); diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c index 7abc4c3a72c..7162f820a03 100644 --- a/dlls/imm32/tests/imm32.c +++ b/dlls/imm32/tests/imm32.c @@ -629,18 +629,19 @@ static void test_ImmGetContext(void) static void test_ImmGetDescription(void) { HKL hkl; - WCHAR japime[] = { 'E', '0', '0', '1', '0', '4', '1', '1', 0 }; WCHAR descW[100]; CHAR descA[100]; UINT ret, lret; /* FIXME: invalid keyboard layouts should not pass */ ret = ImmGetDescriptionW(NULL, NULL, 0); - todo_wine ok(!ret, "ImmGetDescriptionW failed, expected 0 received %d.\n", ret); + ok(!ret, "ImmGetDescriptionW failed, expected 0 received %d.\n", ret); + ret = ImmGetDescriptionA(NULL, NULL, 0); + ok(!ret, "ImmGetDescriptionA failed, expected 0 received %d.\n", ret); /* load a language with valid IMM descriptions */ - hkl = LoadKeyboardLayoutW(japime, KLF_ACTIVATE); - todo_wine ok(hkl != 0, "LoadKeyboardLayoutW failed, expected != 0.\n"); + hkl = GetKeyboardLayout(0); + ok(hkl != 0, "GetKeyboardLayout failed, expected != 0.\n"); ret = ImmGetDescriptionW(hkl, NULL, 0); if(!ret) @@ -649,6 +650,12 @@ static void test_ImmGetDescription(void) return; } + SetLastError(0xdeadcafe); + ret = ImmGetDescriptionW(0, NULL, 100); + ok (ret == 0, "ImmGetDescriptionW with 0 hkl should return 0\n"); + ret = GetLastError(); + ok (ret == 0xdeadcafe, "Last Error should remain unchanged\n"); + ret = ImmGetDescriptionW(hkl, descW, 0); ok(ret, "ImmGetDescriptionW failed, expected != 0 received 0.\n");