From 59be73c0b63436a0e24158d576d30e590b662f01 Mon Sep 17 00:00:00 2001 From: Ari Leviatan Date: Wed, 29 Nov 2023 10:49:18 +0100 Subject: [PATCH] SwiftWin32: compensate for `GetComputerNameW`'s disregard of the null terminator --- Sources/SwiftWin32/App and Environment/Device.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftWin32/App and Environment/Device.swift b/Sources/SwiftWin32/App and Environment/Device.swift index dd3b0765..65d715ae 100644 --- a/Sources/SwiftWin32/App and Environment/Device.swift +++ b/Sources/SwiftWin32/App and Environment/Device.swift @@ -15,7 +15,7 @@ public struct Device { let value: [WCHAR] = Array(unsafeUninitializedCapacity: Int(MAX_COMPUTERNAME_LENGTH) + 1) { var nSize: DWORD = DWORD($0.count) - $1 = GetComputerNameW($0.baseAddress!, &nSize) ? Int(nSize) : 0 + $1 = GetComputerNameW($0.baseAddress!, &nSize) ? Int(nSize) + 1 : 0 } return String(decodingCString: value, as: UTF16.self) }