Akihiro Sagawa : advapi32: Improve load_string to return error code.

Alexandre Julliard julliard at winehq.org
Mon May 13 16:24:17 CDT 2019


Module: wine
Branch: master
Commit: bfdfe85229b94bc8e9e033ab85f641e23077c6eb
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bfdfe85229b94bc8e9e033ab85f641e23077c6eb

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Thu May  9 22:07:30 2019 +0900

advapi32: Improve load_string to return error code.

Signed-off-by: Akihiro Sagawa <sagawa.aki at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/advapi32/registry.c       | 19 +++++++++++--------
 dlls/advapi32/tests/registry.c |  2 +-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index a9a5841..328ae39 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -3112,7 +3112,7 @@ LSTATUS WINAPI RegOpenUserClassesRoot(
  * avoid importing user32, which is higher level than advapi32. Helper for
  * RegLoadMUIString.
  */
-static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
+static LONG load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
 {
     HGLOBAL hMemory;
     HRSRC hResource;
@@ -3125,17 +3125,17 @@ static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMa
 
     /* Load the resource into memory and get a pointer to it. */
     hResource = FindResourceW(hModule, MAKEINTRESOURCEW(LOWORD(resId >> 4) + 1), (LPWSTR)RT_STRING);
-    if (!hResource) return 0;
+    if (!hResource) return ERROR_FILE_NOT_FOUND;
     hMemory = LoadResource(hModule, hResource);
-    if (!hMemory) return 0;
+    if (!hMemory) return ERROR_FILE_NOT_FOUND;
     pString = LockResource(hMemory);
 
     /* Strings are length-prefixed. Lowest nibble of resId is an index. */
     idxString = resId & 0xf;
     while (idxString--) pString += *pString + 1;
 
-    /* If no buffer is given, return length of the string. */
-    if (!pwszBuffer) return *pString;
+    /* If no buffer is given, return here. */
+    if (!pwszBuffer) return ERROR_MORE_DATA;
 
     /* Else copy over the string, respecting the buffer size. */
     cMaxChars = (*pString < cMaxChars) ? *pString : (cMaxChars - 1);
@@ -3144,7 +3144,7 @@ static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMa
         pwszBuffer[cMaxChars] = '\0';
     }
 
-    return cMaxChars;
+    return ERROR_SUCCESS;
 }
 
 /******************************************************************************
@@ -3263,9 +3263,12 @@ LSTATUS WINAPI RegLoadMUIStringW(HKEY hKey, LPCWSTR pwszValue, LPWSTR pwszBuffer
         /* Load the file */
         hModule = LoadLibraryExW(pwszTempBuffer, NULL,
                                  LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
-        if (!hModule || !load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR)))
+        if (hModule) {
+            result = load_string(hModule, uiStringId, pwszBuffer, cbBuffer/sizeof(WCHAR));
+            FreeLibrary(hModule);
+        }
+        else
             result = ERROR_BADKEY;
-        FreeLibrary(hModule);
     }
 
 cleanup:
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index ccda877..cadb936 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -3891,7 +3891,7 @@ static void test_RegLoadMUIString(void)
 
     size = 0xdeadbeef;
     ret = pRegLoadMUIStringW(hkey, tz_valueW, NULL, 0, &size, 0, NULL);
-    todo_wine ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
+    ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
     todo_wine ok(size == text_size, "got %u, expected %u\n", size, text_size);
 
     memset(bufW, 0xff, sizeof(bufW));




More information about the wine-cvs mailing list