mstorsjo created this revision. mstorsjo added a reviewer: aaron.ballman. mstorsjo requested review of this revision. Herald added a project: clang.
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). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D113264 Files: clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp Index: clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp =================================================================== --- clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp +++ clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp @@ -88,10 +88,15 @@ // 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);
Index: clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp =================================================================== --- clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp +++ clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp @@ -88,10 +88,15 @@ // 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits