Module: wine Branch: master Commit: 726027d60182db021edfdf83f1ec39f17486fd5d URL: https://gitlab.winehq.org/wine/wine/-/commit/726027d60182db021edfdf83f1ec39f...
Author: Paul Gofman pgofman@codeweavers.com Date: Wed Nov 8 17:32:04 2023 -0600
user32: Return empty string from LoadStringW() if resource is not found.
---
dlls/user32/resource.c | 13 +++++++------ dlls/user32/tests/resource.c | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c index 3714b05ce8d..d2937988765 100644 --- a/dlls/user32/resource.c +++ b/dlls/user32/resource.c @@ -161,12 +161,13 @@ INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id, if(buffer == NULL) return 0;
- /* Use loword (incremented by 1) as resourceid */ - hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), - (LPWSTR)RT_STRING ); - if (!hrsrc) return 0; - hmem = LoadResource( instance, hrsrc ); - if (!hmem) return 0; + if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING )) || + !(hmem = LoadResource( instance, hrsrc ))) + { + TRACE( "Failed to load string.\n" ); + if (buflen > 0) buffer[0] = 0; + return 0; + }
p = LockResource(hmem); string_num = resource_id & 0x000f; diff --git a/dlls/user32/tests/resource.c b/dlls/user32/tests/resource.c index 2369aef2a09..da4efd2465f 100644 --- a/dlls/user32/tests/resource.c +++ b/dlls/user32/tests/resource.c @@ -120,6 +120,33 @@ static void test_LoadStringW(void) winetest_pop_context(); } } + + /* Test missing resource. */ + SetLastError(0xdeadbeef); + memset(returnedstringw, 0xcc, sizeof(returnedstringw)); + length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, ARRAY_SIZE(returnedstringw)); + ok(!length1, "got %d.\n", length1); + ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_FOUND) /* Win7 */, + "got %lu.\n", GetLastError()); + ok(!returnedstringw[0], "got %#x.\n", returnedstringw[0]); + ok(returnedstringw[1] == 0xcccc, "got %#x.\n", returnedstringw[1]); + + SetLastError(0xdeadbeef); + memset(returnedstringw, 0xcc, sizeof(returnedstringw)); + length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, 0); + ok(!length1, "got %d.\n", length1); + ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_LOADED) /* Win7 */, + "got %lu.\n", GetLastError()); + ok(returnedstringw[0] == 0xcccc, "got %#x.\n", returnedstringw[1]); + + SetLastError(0xdeadbeef); + memset(returnedstringw, 0xcc, sizeof(returnedstringw)); + length1 = LoadStringW(hInst, 0xdeadbeef, returnedstringw, 1); + ok(!length1, "got %d.\n", length1); + ok(GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND || broken(GetLastError() == ERROR_MUI_FILE_NOT_LOADED) /* Win7 */, + "got %lu.\n", GetLastError()); + ok(!returnedstringw[0], "got %#x.\n", returnedstringw[0]); + ok(returnedstringw[1] == 0xcccc, "got %#x.\n", returnedstringw[1]); }
static void test_LoadStringA (void)