Skip to content

Commit

Permalink
Fix bug of missing trailing \0
Browse files Browse the repository at this point in the history
  • Loading branch information
CrendKing committed Apr 22, 2021
1 parent 9261c7b commit 1d32d24
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ auto Environment::QuotePath(PCWSTR path) const -> const WCHAR * {
auto Environment::LoadSelectedItem() -> void {
if (_mappingBuffer != nullptr) {
selectedItem.name = _mappingBuffer;
selectedItem.isFolder = PathIsDirectoryW(_mappingBuffer);
selectedItem.isFolder = PathIsDirectoryW(_mappingBuffer) == FILE_ATTRIBUTE_DIRECTORY;
}
}

auto Environment::FlushSelectedItem() const -> void {
if (selectedItem.name.empty()) {
CopyMemory(_mappingBuffer, L"\0", sizeof(WCHAR));
} else {
CopyMemory(_mappingBuffer, selectedItem.name.c_str(), selectedItem.name.size() * sizeof(WCHAR));
}
// include the tailing L'\0'
CopyMemory(_mappingBuffer, selectedItem.name.c_str(), (selectedItem.name.size() + 1) * sizeof(WCHAR));
}

0 comments on commit 1d32d24

Please sign in to comment.