mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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.
This commit is contained in:
@@ -861,17 +861,17 @@ std::string SwiftLangSupport::resolvePathSymlinks(StringRef FilePath) {
|
||||
if (fileHandle == INVALID_HANDLE_VALUE)
|
||||
return InputPath;
|
||||
|
||||
bool success = GetFinalPathNameByHandleW(fileHandle, full_path, MAX_PATH,
|
||||
DWORD numChars = GetFinalPathNameByHandleW(fileHandle, full_path, MAX_PATH,
|
||||
FILE_NAME_NORMALIZED);
|
||||
CloseHandle(fileHandle);
|
||||
std::string utf8Path;
|
||||
if (success) {
|
||||
if (numChars > 0 && numChars <= MAX_PATH) {
|
||||
llvm::ArrayRef<char> pathRef((const char *)full_path,
|
||||
(const char *)(full_path + MAX_PATH));
|
||||
success &= llvm::convertUTF16ToUTF8String(pathRef, utf8Path);
|
||||
(const char *)(full_path + numChars));
|
||||
return llvm::convertUTF16ToUTF8String(pathRef, utf8Path) ? utf8Path
|
||||
: InputPath;
|
||||
}
|
||||
|
||||
return (success ? utf8Path : InputPath);
|
||||
return InputPath;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user