From 1d32d2451442c0bc09ed77a19256b339f66fddbd Mon Sep 17 00:00:00 2001 From: Crend King <975235+CrendKing@users.noreply.github.com> Date: Thu, 22 Apr 2021 15:34:29 -0700 Subject: [PATCH] Fix bug of missing trailing \0 --- src/environment.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index 4d7b333..89b4181 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -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)); }