From f6e1f6dae806b4306d2d43db39948b8c09aad2bf Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Mon, 30 Oct 2023 04:13:30 +0100 Subject: [PATCH] Fix string view of reallocated string. (#14) --- source/FileEnumerator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/FileEnumerator.h b/source/FileEnumerator.h index e54188d9..a73852d3 100644 --- a/source/FileEnumerator.h +++ b/source/FileEnumerator.h @@ -36,7 +36,7 @@ void FilesWalk(const char* directory, const char* extension, T callback) std::string pattern = directory; if(!pattern.empty() && pattern.back() != '\\') pattern.push_back('\\'); - std::string_view baseDir = pattern; + const size_t baseDirLen = pattern.length(); pattern.push_back('*'); if (extension != nullptr) pattern.append(extension); @@ -56,7 +56,7 @@ void FilesWalk(const char* directory, const char* extension, T callback) continue; // skip directories } - auto result = std::filesystem::weakly_canonical(std::string(baseDir) + wfd.cFileName); // will use CWD if input path was relative! + auto result = std::filesystem::weakly_canonical(pattern.substr(0, baseDirLen) + wfd.cFileName); // will use CWD if input path was relative! callback(result.string().c_str(), result.filename().string().c_str()); } while (FindNextFile(hSearch, &wfd));