Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd147c8

Browse files
authored
SwiftWin32: compensate for GetComputerNameW's disregard of the null terminator
### Issue `GetComputerNameW` disregards the null terminator when returning the size of the buffer. This leads to the following error when using `Device.name`: `Swift/CString.swift:284: Fatal error: input of decodeCString(_:as:repairingInvalidCodeUnits:) must be null-terminated` ### Solution Compensated the buffer size to account for the null terminator.
1 parent fe0b6b8 commit fd147c8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎Sources/SwiftWin32/App and Environment/Device.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct Device {
1515
let value: [WCHAR] =
1616
Array<WCHAR>(unsafeUninitializedCapacity: Int(MAX_COMPUTERNAME_LENGTH) + 1) {
1717
var nSize: DWORD = DWORD(0ドル.count)
18-
1ドル = GetComputerNameW(0ドル.baseAddress!, &nSize) ? Int(nSize) : 0
18+
1ドル = GetComputerNameW(0ドル.baseAddress!, &nSize) ? Int(nSize) +1: 0
1919
}
2020
return String(decodingCString: value, as: UTF16.self)
2121
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /