Skip to content

Commit 1864abd

Browse files
committed
GetSystemWindowsDirectoryW doesn't like nil buffers
1 parent 906be42 commit 1864abd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/Testing/Support/FileHandle.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,9 @@ let rootDirectoryPath: String = {
732732
// contains the system Windows directory. For an explanation of the difference
733733
// between the Windows directory and the _system_ Windows directory, see
734734
// https://devblogs.microsoft.com/oldnewthing/20140723-00/?p=423 .
735-
let count = GetSystemWindowsDirectoryW(nil, 0)
735+
let count = withUnsafeTemporaryAllocation(of: wchar_t.self, capacity: 1) { buffer in
736+
GetSystemWindowsDirectoryW(buffer.baseAddress!, buffer.count)
737+
}
736738
if count > 0 {
737739
withUnsafeTemporaryAllocation(of: wchar_t.self, capacity: Int(count) + 1) { buffer in
738740
_ = GetSystemWindowsDirectoryW(buffer.baseAddress!, UINT(buffer.count))

0 commit comments

Comments
 (0)