Skip to content

Commit

Permalink
Fix string view of reallocated string. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC authored Oct 30, 2023
1 parent 1ff1b4b commit f6e1f6d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/FileEnumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down

0 comments on commit f6e1f6d

Please sign in to comment.