Author: Martin Storsjö
Date: 2021-11-08T22:21:30+02:00
New Revision: 2ca6fc34fc08eaadb0f287a7f1b33bc1de4d1bd6

URL: 
https://github.com/llvm/llvm-project/commit/2ca6fc34fc08eaadb0f287a7f1b33bc1de4d1bd6
DIFF: 
https://github.com/llvm/llvm-project/commit/2ca6fc34fc08eaadb0f287a7f1b33bc1de4d1bd6.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp 
b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
index 1f040f60ff19d..110d402436ee9 100644
--- a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
+++ b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
@@ -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);


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to