diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index e4d4893bd42..1f335b1c9f3 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -1081,6 +1081,11 @@ static void test_reg_open_key(void) ok(!RegCloseKey(hkResult), "got invalid hkey\n"); /* empty subkey of NULL */ + hkResult = hkPreserve; + ret = RegOpenKeyExW(NULL, L"", 0, KEY_QUERY_VALUE, &hkResult); + ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret); + ok(hkResult == NULL || broken(hkResult == hkPreserve /* Windows XP */), "expected hkResult == NULL\n"); + hkResult = hkPreserve; ret = RegOpenKeyExA(NULL, "", 0, KEY_QUERY_VALUE, &hkResult); ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret); diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index e6f3722f70e..f8afb94f8d2 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -479,6 +479,7 @@ LSTATUS WINAPI DECLSPEC_HOTPATCH RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD o if (HandleToUlong(hkey) == HandleToUlong(HKEY_CLASSES_ROOT) && name && *name == '\\') name++; if (!retkey) return ERROR_INVALID_PARAMETER; + *retkey = NULL; if (!(hkey = get_special_root_hkey( hkey, access ))) return ERROR_INVALID_HANDLE; attr.Length = sizeof(attr);