Skip to content

Commit 2ca6fc3

Browse files
committed
[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
1 parent 46ec93a commit 2ca6fc3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ DirectoryWatcherWindows::DirectoryWatcherWindows(
8888
// handle to the watcher and performing synchronous operations.
8989
{
9090
DWORD Size = GetFinalPathNameByHandleW(DirectoryHandle, NULL, 0, 0);
91-
std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size]};
91+
std::unique_ptr<WCHAR[]> Buffer{new WCHAR[Size + 1]};
9292
Size = GetFinalPathNameByHandleW(DirectoryHandle, Buffer.get(), Size, 0);
9393
Buffer[Size] = L'\0';
94-
llvm::sys::windows::UTF16ToUTF8(Buffer.get(), Size, Path);
94+
WCHAR *Data = Buffer.get();
95+
if (Size >= 4 && ::memcmp(Data, L"\\\\?\\", 8) == 0) {
96+
Data += 4;
97+
Size -= 4;
98+
}
99+
llvm::sys::windows::UTF16ToUTF8(Data, Size, Path);
95100
}
96101

97102
size_t EntrySize = sizeof(FILE_NOTIFY_INFORMATION) + MAX_PATH * sizeof(WCHAR);

0 commit comments

Comments
 (0)