comphelper/source/windows/windows_process.cxx | 14 +++++--------- desktop/source/app/updater.cxx | 8 +++----- include/comphelper/windowsStart.hxx | 5 ++--- 3 files changed, 10 insertions(+), 17 deletions(-)
New commits: commit 9e4114e2cc9473cc3d4cf055a3f50e6d0115a1d0 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jan 8 13:52:01 2025 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Jan 8 16:10:03 2025 +0100 Simplify a bit WinLaunchChild takes the same kind of argv as execv, terminated by a null pointer; so no need to pass argc. Change-Id: I280c8da0c613a7d0d1a208831a87f0e4648719f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179952 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/comphelper/source/windows/windows_process.cxx b/comphelper/source/windows/windows_process.cxx index fc91145bbbf2..12c14dff1ec3 100644 --- a/comphelper/source/windows/windows_process.cxx +++ b/comphelper/source/windows/windows_process.cxx @@ -126,17 +126,14 @@ static wchar_t* ArgToString(wchar_t *d, const wchar_t *s) /** * Creates a command line from a list of arguments. The returned * string is allocated with "malloc" and should be "free"d. - * - * argv is UTF8 */ -wchar_t* -MakeCommandLine(int argc, wchar_t **argv) +static wchar_t* MakeCommandLine(wchar_t **argv) { int i; int len = 0; // The + 1 of the last argument handles the allocation for null termination - for (i = 0; i < argc && argv[i]; ++i) + for (i = 0; argv[i]; ++i) len += ArgStrLen(argv[i]) + 1; // Protect against callers that pass 0 arguments @@ -148,10 +145,10 @@ MakeCommandLine(int argc, wchar_t **argv) return nullptr; wchar_t *c = s; - for (i = 0; i < argc && argv[i]; ++i) + for (i = 0; argv[i]; ++i) { c = ArgToString(c, argv[i]); - if (i + 1 != argc) + if (argv[i + 1]) { *c = ' '; ++c; @@ -165,7 +162,6 @@ MakeCommandLine(int argc, wchar_t **argv) BOOL WinLaunchChild(const wchar_t *exePath, - int argc, wchar_t **argv, HANDLE userToken, HANDLE *hProcess) @@ -173,7 +169,7 @@ WinLaunchChild(const wchar_t *exePath, wchar_t *cl; bool ok; - cl = MakeCommandLine(argc, argv); + cl = MakeCommandLine(argv); if (!cl) { return FALSE; diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx index a52554978b28..ce0836b6511b 100644 --- a/desktop/source/app/updater.cxx +++ b/desktop/source/app/updater.cxx @@ -175,7 +175,7 @@ void createStr(const OUString& rStr, CharT** pArgs, size_t i) pArgs[i] = pStr; } -CharT** createCommandLine(OUString const & argv0, int * argc) +CharT** createCommandLine(OUString const & argv0) { OUString aInstallDir = Updater::getInstallationPath(); @@ -238,7 +238,6 @@ CharT** createCommandLine(OUString const & argv0, int * argc) pArgs[nArgs - 1] = nullptr; - *argc = nArgs - 1; return pArgs; } @@ -305,8 +304,7 @@ bool update() OUString aUpdaterPath = getPathFromURL(aTempDirURL + "/" + OUString::fromUtf8(pUpdaterName)); Updater::log("Calling the updater with parameters: "); - int argc; - CharT** pArgs = createCommandLine(aUpdaterPath, &argc); + CharT** pArgs = createCommandLine(aUpdaterPath); bool bSuccess = true; const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE"); @@ -320,7 +318,7 @@ bool update() bSuccess = false; } #elif defined(_WIN32) - bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), argc, pArgs); + bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), pArgs); #endif } else diff --git a/include/comphelper/windowsStart.hxx b/include/comphelper/windowsStart.hxx index a727733d92a3..112a0b3250e2 100644 --- a/include/comphelper/windowsStart.hxx +++ b/include/comphelper/windowsStart.hxx @@ -15,13 +15,12 @@ /** * Launch a child process with the specified arguments. + * argv must be terminated by a null pointer, similar to execv. * @note argv[0] is ignored */ BOOL -WinLaunchChild(const wchar_t *exePath, int argc, +WinLaunchChild(const wchar_t *exePath, wchar_t **argv, HANDLE userToken = nullptr, HANDLE *hProcess = nullptr); -wchar_t* MakeCommandLine(int argc, wchar_t **argv); - #endif