From d32bd86a6b4fc1ea7d787be13d6f1a002780ba37 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 29 Sep 2020 22:45:41 +0200 Subject: [PATCH] Skip leading path separators in the relative JRE path. --- src/head.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/head.c b/src/head.c index 92ab10b..00e8ff7 100644 --- a/src/head.c +++ b/src/head.c @@ -233,7 +233,7 @@ static wchar_t *get_path_without_suffix(const wchar_t *const path) static wchar_t * trim_trailing_separator(wchar_t *const path) { - if(NOT_EMPTY(path)) + if (NOT_EMPTY(path)) { size_t len = wcslen(path); while ((len > 0U) && ((path[len-1U] == L'\\') || (path[len-1U] == L'/'))) @@ -244,6 +244,15 @@ static wchar_t * trim_trailing_separator(wchar_t *const path) return path; } +static const wchar_t *skip_leading_separator(const wchar_t *path) +{ + if (NOT_EMPTY(path)) + { + for (; (*path) && ((*path == L'\\') || (*path == L'/')); ++path); + } + return path; +} + static BOOL file_exists(const wchar_t *const filename) { struct _stat buffer; if (_wstat(filename, &buffer) == 0) @@ -1104,7 +1113,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine } #else jre_relative_path = load_string(hInstance, ID_STR_JREPATH); - if (!(java_runtime_path = awprintf(L"%ls\\%ls", executable_directory, AVAILABLE(jre_relative_path) ? jre_relative_path: JRE_RELATIVE_PATH_DEFAULT))) + if (!(java_runtime_path = awprintf(L"%ls\\%ls", executable_directory, AVAILABLE(jre_relative_path) ? skip_leading_separator(jre_relative_path) : JRE_RELATIVE_PATH_DEFAULT))) { show_message(hwnd, MB_ICONERROR | MB_TOPMOST, APP_HEADING, L"The path of the Java runtime could not be determined!"); goto cleanup;