diff --git a/nsis/winpath.cpp b/nsis/winpath.cpp index e8e1bfae83..72d770c133 100644 --- a/nsis/winpath.cpp +++ b/nsis/winpath.cpp @@ -15,24 +15,21 @@ // This will start a Windows command line with PATH extended by // the location of the winpath executable. +#include // std::filesystem::path #include // _spawnvp -#include // _putenv_s -#include // strcpy, strcat - -static char path[4096]; +#include // _putenv_s, getenv +#include // std::string int main(int argc, char *argv[]) { if (argc > 1) { - char *dir = argv[0]; - char *last = strrchr(dir, '\\'); - if (last != nullptr) { - *last = '\0'; - } - strcpy(path, dir); - strcat(path, ";"); - strcat(path, getenv("PATH")); - _putenv_s("PATH", path); - _spawnvp(_P_WAIT, argv[1], argv + 1); + std::filesystem::path exe_path(argv[0]); + std::string dir = exe_path.parent_path().string(); + + const char *env_path = getenv("PATH"); + std::string new_path = dir + ";" + (env_path ? env_path : ""); + + _putenv_s("PATH", new_path.c_str()); + return _spawnvp(_P_WAIT, argv[1], argv + 1); //~ _spawnvp(_P_OVERLAY, argv[1], argv + 1); } return 0;