diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 428ea10e2d3..063fe4cdc6d 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; + WCHAR* p; + unsigned sym_path_len; + unsigned alt_sym_path_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)); + sym_path_len = GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", NULL, 0); + alt_sym_path_len = GetEnvironmentVariableW(L"_NT_ALTERNATE_SYMBOL_PATH", NULL, 0); - len = GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", NULL, 0); - if (len) + /* 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); }