desktop/win32/source/applauncher/launcher.cxx | 21 +++++++-------------- sal/osl/all/log.cxx | 18 +++++++++--------- 2 files changed, 16 insertions(+), 23 deletions(-)
New commits: commit a9e1fb692167d838a207abfd72ae04f2821b9dc6 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Feb 25 19:26:14 2024 +0600 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Feb 26 04:17:49 2024 +0100 Use filesystem::path to avoid MAX_PATH limitation And use a buffer of 32767 characters, which is the approximate maximum of Windows API, as documented in https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Change-Id: I7ee3283a98ebc72e7d79aacc65b01fdb7eeccd83 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163919 Tested-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/desktop/win32/source/applauncher/launcher.cxx b/desktop/win32/source/applauncher/launcher.cxx index bf80dba2cc5a..044b02d1ef33 100644 --- a/desktop/win32/source/applauncher/launcher.cxx +++ b/desktop/win32/source/applauncher/launcher.cxx @@ -19,6 +19,7 @@ #include "launcher.hxx" +#include <filesystem> #include <stdlib.h> #include <malloc.h> @@ -26,10 +27,7 @@ extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) { // Retrieve startup info - STARTUPINFOW aStartupInfo; - - ZeroMemory( &aStartupInfo, sizeof(aStartupInfo) ); - aStartupInfo.cb = sizeof( aStartupInfo ); + STARTUPINFOW aStartupInfo{ sizeof(aStartupInfo) }; GetStartupInfoW( &aStartupInfo ); // Retrieve command line @@ -42,20 +40,15 @@ extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) // Calculate application name - WCHAR szApplicationName[MAX_PATH]; - WCHAR szDrive[MAX_PATH]; - WCHAR szDir[MAX_PATH]; - WCHAR szFileName[MAX_PATH]; - WCHAR szExt[MAX_PATH]; - - GetModuleFileNameW( nullptr, szApplicationName, MAX_PATH ); - _wsplitpath( szApplicationName, szDrive, szDir, szFileName, szExt ); - _wmakepath( szApplicationName, szDrive, szDir, L"soffice", L".exe" ); + WCHAR szThisAppName[32767]; + GetModuleFileNameW(nullptr, szThisAppName, std::size(szThisAppName)); + std::filesystem::path soffice_exe(szThisAppName); + soffice_exe.replace_filename(L"soffice.exe"); PROCESS_INFORMATION aProcessInfo; bool fSuccess = CreateProcessW( - szApplicationName, + soffice_exe.c_str(), lpCommandLine, nullptr, nullptr, commit 119588ad23fc2a1e44e073b5f9de972c49f7ba60 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Feb 25 19:25:12 2024 +0600 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Feb 26 04:17:37 2024 +0100 Use filesystem::path to avoid MAX_PATH limitation And use a buffer of 32767 characters, which is the approximate maximum of Windows API, as documented in https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Change-Id: I7b5329d48c936ce0090f0c7908a9d08b56b5a734 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163918 Tested-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 15cb269a1976..d014b2950d3e 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -15,6 +15,7 @@ #include <cstdlib> #include <cstring> +#include <filesystem> #include <fstream> #include <config_global.h> @@ -90,26 +91,25 @@ char const * toString(sal_detail_LogLevel level) { char const* setEnvFromLoggingIniFile(const char* env, const char* key) { char const* sResult = nullptr; - wchar_t buffer[MAX_PATH]; - GetModuleFileNameW(nullptr, buffer, MAX_PATH); - std::wstring sProgramDirectory(buffer); - std::wstring::size_type pos = sProgramDirectory.find_last_of(L"\/"); - sProgramDirectory = sProgramDirectory.substr(0, pos+1); - sProgramDirectory += L"logging.ini"; + wchar_t buffer[32767]; + DWORD nLen = GetModuleFileNameW(nullptr, buffer, std::size(buffer)); + if (nLen == 0 || nLen >= std::size(buffer)) + return sResult; + std::filesystem::path sProgramDirectory(std::wstring(buffer, nLen)); + sProgramDirectory.replace_filename(L"logging.ini"); std::ifstream logFileStream(sProgramDirectory); if (!logFileStream.good()) return sResult; std::size_t n; - std::string aKey; - std::string sWantedKey(key); + std::string_view sWantedKey(key); std::string sLine; while (std::getline(logFileStream, sLine)) { if (sLine.find('#') == 0) continue; if ( ( n = sLine.find('=') ) != std::string::npos) { - aKey = sLine.substr(0, n); + std::string_view aKey(sLine.data(), n); if (aKey != sWantedKey) continue; _putenv_s(env, sLine.substr(n+1, sLine.length()).c_str());