Skip to content

Commit 77c2687

Browse files
committed
[Windows] Fix resolvePathSymlinks
The llvm::ArrayRef constructor should be passed the actual length of the resulting string, not MAX_PATH, else the StringRef that results has an incorrect length of MAX_PATH.
1 parent f70c41b commit 77c2687

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,17 +861,17 @@ std::string SwiftLangSupport::resolvePathSymlinks(StringRef FilePath) {
861861
if (fileHandle == INVALID_HANDLE_VALUE)
862862
return InputPath;
863863

864-
bool success = GetFinalPathNameByHandleW(fileHandle, full_path, MAX_PATH,
864+
DWORD numChars = GetFinalPathNameByHandleW(fileHandle, full_path, MAX_PATH,
865865
FILE_NAME_NORMALIZED);
866866
CloseHandle(fileHandle);
867867
std::string utf8Path;
868-
if (success) {
868+
if (numChars > 0 && numChars <= MAX_PATH) {
869869
llvm::ArrayRef<char> pathRef((const char *)full_path,
870-
(const char *)(full_path + MAX_PATH));
871-
success &= llvm::convertUTF16ToUTF8String(pathRef, utf8Path);
870+
(const char *)(full_path + numChars));
871+
return llvm::convertUTF16ToUTF8String(pathRef, utf8Path) ? utf8Path
872+
: InputPath;
872873
}
873-
874-
return (success ? utf8Path : InputPath);
874+
return InputPath;
875875
#endif
876876
}
877877

0 commit comments

Comments
 (0)