From 56b4b010d6d1e725ad033a7f3f3e0bb23e76cdcc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Apr 2020 15:57:53 +0200 Subject: [PATCH] fs/FileSystem, ...: use AllocatedPath::FromFS(string_view) --- src/fs/FileSystem.cxx | 3 +-- src/fs/LookupFile.cxx | 2 +- src/fs/NarrowPath.cxx | 2 +- src/fs/StandardDirectory.cxx | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fs/FileSystem.cxx b/src/fs/FileSystem.cxx index 31773aa88..92ab42881 100644 --- a/src/fs/FileSystem.cxx +++ b/src/fs/FileSystem.cxx @@ -55,8 +55,7 @@ ReadLink(Path path) errno = ENOMEM; return nullptr; } - buffer[size] = '\0'; - return AllocatedPath::FromFS(buffer); + return AllocatedPath::FromFS(std::string_view{buffer, size_t(size)}); #endif } diff --git a/src/fs/LookupFile.cxx b/src/fs/LookupFile.cxx index 8af0bb197..5d925c124 100644 --- a/src/fs/LookupFile.cxx +++ b/src/fs/LookupFile.cxx @@ -52,7 +52,7 @@ LookupFile(Path pathname) //its a file ? if (file_info.IsRegular()) { //so the upper should be file - return {AllocatedPath::FromFS(buffer.c_str()), AllocatedPath::FromFS(slash + 1)}; + return {AllocatedPath::FromFS(buffer), AllocatedPath::FromFS(slash + 1)}; } else { return {}; } diff --git a/src/fs/NarrowPath.cxx b/src/fs/NarrowPath.cxx index e2597f83f..596e46de6 100644 --- a/src/fs/NarrowPath.cxx +++ b/src/fs/NarrowPath.cxx @@ -43,7 +43,7 @@ AcpToAllocatedPath(const char *s) if (result <= 0) throw MakeLastError("MultiByteToWideChar() failed"); - return AllocatedPath::FromFS(buffer); + return AllocatedPath::FromFS(std::wstring_view(buffer, result)); } FromNarrowPath::FromNarrowPath(const char *s) diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index d5e51e2f7..c80ebdeef 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -303,7 +303,7 @@ GetAppBaseDir() noexcept if (ret == app.size() && GetLastError() == ERROR_INSUFFICIENT_BUFFER) return nullptr; - auto app_path = AllocatedPath::FromFS(app.data()); + auto app_path = AllocatedPath::FromFS(PathTraitsFS::string_view(app.data(), ret)); return app_path.GetDirectoryName().GetDirectoryName(); }