[PATCH 3/4] dbghelp: Use . instead of concrete path for search path.

Thomas Faber thomas.faber at reactos.org
Sun Nov 14 07:39:39 CST 2021


From 9b05436fa31d9d3a5d16624fe5a7d85ebf2bf2ab Mon Sep 17 00:00:00 2001
From: Thomas Faber <thomas.faber at reactos.org>
Date: Fri, 12 Nov 2021 18:17:53 -0500
Subject: dbghelp: Use . instead of concrete path for search path.

Signed-off-by: Thomas Faber <thomas.faber at reactos.org>
---
 dlls/dbghelp/dbghelp.c       | 45 +++++++++++++++++++++---------------
 dlls/dbghelp/tests/dbghelp.c |  4 ----
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c
index 75d68c34971..b65da2db88b 100644
--- a/dlls/dbghelp/dbghelp.c
+++ b/dlls/dbghelp/dbghelp.c
@@ -178,29 +178,36 @@ struct cpu* cpu_find(DWORD machine)
 static WCHAR* make_default_search_path(void)
 {
     WCHAR*      search_path;
-    unsigned    size;
-    unsigned    len;
-
-    search_path = HeapAlloc(GetProcessHeap(), 0, (len = MAX_PATH) * sizeof(WCHAR));
-    while ((size = GetCurrentDirectoryW(len, search_path)) >= len)
-        search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (len *= 2) * sizeof(WCHAR));
-    search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1) * sizeof(WCHAR));
-
-    len = GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", NULL, 0);
-    if (len)
+    WCHAR*      p;
+    unsigned    sym_path_len;
+    unsigned    alt_sym_path_len;
+
+    sym_path_len = GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", NULL, 0);
+    alt_sym_path_len = GetEnvironmentVariableW(L"_NT_ALTERNATE_SYMBOL_PATH", NULL, 0);
+
+    /* The default symbol path is ".[;%_NT_SYMBOL_PATH%][;%_NT_ALTERNATE_SYMBOL_PATH%]".
+     * If the variables exist, the lengths include a null-terminator. We use that
+     * space for the semicolons, and only add the initial dot and the final null. */
+    search_path = HeapAlloc(GetProcessHeap(), 0,
+                            (1 + sym_path_len + alt_sym_path_len + 1) * sizeof(WCHAR));
+    if (!search_path) return NULL;
+
+    p = search_path;
+    *p++ = L'.';
+    if (sym_path_len)
     {
-        search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR));
-        search_path[size] = ';';
-        GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", search_path + size + 1, len);
-        size += 1 + len;
+        *p++ = L';';
+        GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", p, sym_path_len);
+        p += sym_path_len - 1;
     }
-    len = GetEnvironmentVariableW(L"_NT_ALTERNATE_SYMBOL_PATH", NULL, 0);
-    if (len)
+
+    if (alt_sym_path_len)
     {
-        search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR));
-        search_path[size] = ';';
-        GetEnvironmentVariableW(L"_NT_ALTERNATE_SYMBOL_PATH", search_path + size + 1, len);
+        *p++ = L';';
+        GetEnvironmentVariableW(L"_NT_ALTERNATE_SYMBOL_PATH", p, alt_sym_path_len);
+        p += alt_sym_path_len - 1;
     }
+    *p = L'\0';
 
     return search_path;
 }
diff --git a/dlls/dbghelp/tests/dbghelp.c b/dlls/dbghelp/tests/dbghelp.c
index 06c21ec288c..a42e83aa2c8 100644
--- a/dlls/dbghelp/tests/dbghelp.c
+++ b/dlls/dbghelp/tests/dbghelp.c
@@ -141,7 +141,6 @@ static void test_search_path(void)
      * We unset both variables earlier so should simply get "." */
     ret = SymGetSearchPath(GetCurrentProcess(), search_path, ARRAY_SIZE(search_path));
     ok(ret == TRUE, "ret = %d\n", ret);
-    todo_wine
     ok(!strcmp(search_path, "."), "Got search path '%s', expected '.'\n", search_path);
 
     /* Set an arbitrary search path */
@@ -156,7 +155,6 @@ static void test_search_path(void)
     ok(ret == TRUE, "ret = %d\n", ret);
     ret = SymGetSearchPath(GetCurrentProcess(), search_path, ARRAY_SIZE(search_path));
     ok(ret == TRUE, "ret = %d\n", ret);
-    todo_wine
     ok(!strcmp(search_path, "."), "Got search path '%s', expected '.'\n", search_path);
 
     /* With _NT_SYMBOL_PATH */
@@ -165,7 +163,6 @@ static void test_search_path(void)
     ok(ret == TRUE, "ret = %d\n", ret);
     ret = SymGetSearchPath(GetCurrentProcess(), search_path, ARRAY_SIZE(search_path));
     ok(ret == TRUE, "ret = %d\n", ret);
-    todo_wine
     ok(!strcmp(search_path, ".;X:\\"), "Got search path '%s', expected '.;X:\\'\n", search_path);
 
     /* With both _NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH */
@@ -192,7 +189,6 @@ static void test_search_path(void)
     ok(ret == TRUE, "ret = %d\n", ret);
     ret = SymGetSearchPath(GetCurrentProcess(), search_path, ARRAY_SIZE(search_path));
     ok(ret == TRUE, "ret = %d\n", ret);
-    todo_wine
     ok(!strcmp(search_path, "."), "Got search path '%s', expected '.'\n", search_path);
 }
 
-- 
2.31.1



More information about the wine-devel mailing list