[clang] [DirectoryWatcher] Remove leading \\?\ from GetFinalPathNameByHandleW

This is needed for the paths to work when using forward slashes;
this fixes the DirectoryWatcherTests unit tests.

Also allocate missing space for the null terminator, which seems to
have been missing all along (writing the terminator out of bounds).

Differential Revision: https://reviews.llvm.org/D113264
This commit is contained in:
Martin Storsjö 2021-10-07 21:14:15 +00:00
parent 46ec93a457
commit 2ca6fc34fc
1 changed files with 7 additions and 2 deletions

View File

@ -88,10 +88,15 @@ DirectoryWatcherWindows::DirectoryWatcherWindows(
// handle to the watcher and performing synchronous operations.
{
DWORD Size = GetFinalPathNameByHandleW(DirectoryHandle, NULL, 0, 0);
std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size]};
std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size + 1]};
Size = GetFinalPathNameByHandleW(DirectoryHandle, Buffer.get(), Size, 0);
Buffer[Size] = L'\0';
llvm::sys::windows::UTF16ToUTF8(Buffer.get(), Size, Path);
WCHAR *Data = Buffer.get();
if (Size >= 4 && ::memcmp(Data, L"\\\\?\\", 8) == 0) {
Data += 4;
Size -= 4;
}
llvm::sys::windows::UTF16ToUTF8(Data, Size, Path);
}
size_t EntrySize = sizeof(FILE_NOTIFY_INFORMATION) + MAX_PATH * sizeof(WCHAR);