From 62f52103646c20e81fe7bb76e51dee1813a82edf Mon Sep 17 00:00:00 2001 From: Akihiro Sagawa Date: Sun, 26 May 2019 21:15:09 +0900 Subject: [PATCH] advapi32: Fix the error code on load failure. Signed-off-by: Akihiro Sagawa Signed-off-by: Alexandre Julliard --- dlls/advapi32/registry.c | 12 ++++++------ dlls/advapi32/tests/registry.c | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index f18e34fe81f..8596aea509d 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -3133,6 +3133,10 @@ static INT load_string(HINSTANCE hModule, UINT resId, LPWSTR *pResString) /* Strings are length-prefixed. Lowest nibble of resId is an index. */ idxString = resId & 0xf; while (idxString--) pString += *pString + 1; + if (!*pString) { + SetLastError(ERROR_NOT_FOUND); + return 0; + } *pResString = pString + 1; return *pString; @@ -3153,11 +3157,11 @@ static LONG load_mui_string(const WCHAR *file_name, UINT res_id, WCHAR *buffer, hModule = LoadLibraryExW(file_name, NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE); if (!hModule) - return ERROR_BADKEY; + return GetLastError(); size = load_string(hModule, res_id, &string); if (!size) { - result = ERROR_FILE_NOT_FOUND; + result = GetLastError(); goto cleanup; } *req_chars = size + 1; @@ -3210,10 +3214,6 @@ cleanup: * RETURNS * Success: ERROR_SUCCESS, * Failure: nonzero error code from winerror.h - * - * NOTES - * This is an API of Windows Vista, which wasn't available at the time this code - * was written. We have to check for the correct behaviour once it's available. */ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer, DWORD cbBuffer, LPDWORD pcbData, DWORD dwFlags, LPCWSTR pwszBaseDir) diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index 0f4e196d0d2..8a2fb3b7a50 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -3854,7 +3854,6 @@ static void test_RegLoadMUIString(void) BOOL use_sysdir; DWORD expected; DWORD broken_ret; - BOOL todo; } test_case[] = { /* 0 */ { "", REG_SZ, FALSE, ERROR_INVALID_DATA }, @@ -3868,9 +3867,9 @@ static void test_RegLoadMUIString(void) { "@%WineMuiTest2%", REG_EXPAND_SZ, TRUE, ERROR_SUCCESS }, /* 8 */ { "@%WineMuiExe%,a", REG_SZ, FALSE, ERROR_INVALID_DATA }, - { "@%WineMuiExe%,-4", REG_SZ, FALSE, ERROR_NOT_FOUND, ERROR_FILE_NOT_FOUND, TRUE }, - { "@%WineMuiExe%,-39", REG_SZ, FALSE, ERROR_RESOURCE_NAME_NOT_FOUND, 0, TRUE }, - { "@%WineMuiDat%,-16", REG_EXPAND_SZ, FALSE, ERROR_BAD_EXE_FORMAT, ERROR_FILE_NOT_FOUND, TRUE }, + { "@%WineMuiExe%,-4", REG_SZ, FALSE, ERROR_NOT_FOUND, ERROR_FILE_NOT_FOUND }, + { "@%WineMuiExe%,-39", REG_SZ, FALSE, ERROR_RESOURCE_NAME_NOT_FOUND }, + { "@%WineMuiDat%,-16", REG_EXPAND_SZ, FALSE, ERROR_BAD_EXE_FORMAT, ERROR_FILE_NOT_FOUND }, }; if (!pRegLoadMUIStringA || !pRegLoadMUIStringW) @@ -4013,7 +4012,6 @@ static void test_RegLoadMUIString(void) ret = pRegLoadMUIStringW(hkey_main, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, test_case[i].use_sysdir ? sysdirW : NULL); - todo_wine_if(test_case[i].todo) ok(ret == test_case[i].expected || broken(test_case[i].value[0] == '%' && ret == ERROR_SUCCESS /* vista */) || broken(test_case[i].broken_ret && ret == test_case[i].broken_ret /* vista */),