summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-01-24 16:52:21 +0600
committerMike Kaganski <mike.kaganski@collabora.com>2024-02-25 07:29:40 +0100
commit3234c4e35fe97cffb87f785614b3b593e2237310 (patch)
tree5bfc988337d90dc895cd56c7b88fffaa70d6747e /tools/source
parentf894670c2cb654a1e21fb34f440977af74e8a560 (diff)
Avoid MAX_PATH limitation in launcher
... and drop some manual memory management. Change-Id: I4c60ce559ff185d4685a6b9799a97651438115b1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162502 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/misc/pathutils.cxx59
1 files changed, 18 insertions, 41 deletions
diff --git a/tools/source/misc/pathutils.cxx b/tools/source/misc/pathutils.cxx
index 706740a320f9..30bdbde8f013 100644
--- a/tools/source/misc/pathutils.cxx
+++ b/tools/source/misc/pathutils.cxx
@@ -43,63 +43,40 @@ WCHAR * filename(WCHAR * path) {
}
}
-WCHAR * buildPath(
- WCHAR * path, WCHAR const * frontBegin, WCHAR const * frontEnd,
- WCHAR const * backBegin, std::size_t backLength)
+std::wstring buildPath(std::wstring_view front, std::wstring_view back)
{
// Remove leading ".." segments in the second path together with matching
// segments in the first path that are neither empty nor "." nor ".." nor
// end in ":" (which is not foolproof, as it can erroneously erase the start
// of a UNC path, but only if the input is bad data):
- while (backLength >= 2 && backBegin[0] == L'.' && backBegin[1] == L'.' &&
- (backLength == 2 || backBegin[2] == L'\\'))
+ while (back.starts_with(L"..") &&
+ (back.size() == 2 || back[2] == L'\\'))
{
- if (frontEnd - frontBegin < 2 || frontEnd[-1] != L'\\' ||
- frontEnd[-2] == L'\\' || frontEnd[-2] == L':' ||
- (frontEnd[-2] == L'.' &&
- (frontEnd - frontBegin < 3 || frontEnd[-3] == L'\\' ||
- (frontEnd[-3] == L'.' &&
- (frontEnd - frontBegin < 4 || frontEnd[-4] == L'\\')))))
+ if (front.size() < 2 || front.back() != L'\\' ||
+ front[front.size() - 2] == L'\\' || front[front.size() - 2] == L':' ||
+ (front[front.size() - 2] == L'.' &&
+ (front.size() < 3 || front[front.size() - 3] == L'\\' ||
+ (front[front.size() - 3] == L'.' &&
+ (front.size() < 4 || front[front.size() - 4] == L'\\')))))
{
break;
}
- WCHAR const * p = frontEnd - 1;
- while (p != frontBegin && p[-1] != L'\\') {
+ auto p = front.end() - 1;
+ while (p != front.begin() && p[-1] != L'\\') {
--p;
}
- if (p == frontBegin) {
+ if (p == front.begin()) {
break;
}
- frontEnd = p;
- if (backLength == 2) {
- backBegin += 2;
- backLength -= 2;
+ front.remove_suffix(front.end() - p);
+ if (back.size() == 2) {
+ back = {};
} else {
- backBegin += 3;
- backLength -= 3;
+ back.remove_prefix(3);
}
}
- if (backLength <
- o3tl::make_unsigned(MAX_PATH - (frontEnd - frontBegin)))
- {
- WCHAR * p;
- if (frontBegin == path) {
- p = const_cast< WCHAR * >(frontEnd);
- } else {
- p = path;
- while (frontBegin != frontEnd) {
- *p++ = *frontBegin++;
- }
- }
- for (; backLength > 0; --backLength) {
- *p++ = *backBegin++;
- }
- *p = L'\0';
- return p;
- } else {
- SetLastError(ERROR_FILENAME_EXCED_RANGE);
- return nullptr;
- }
+
+ return std::wstring(front) + std::wstring(back);
}
}