Skip to content

Commit a750432

Browse files
committed
Views and Control: correct Label content access
`GetWindowTextW` is documented as: ``` If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating null character. ``` Ensure that we properly account for the trailing null character.
1 parent 7815970 commit a750432

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/SwiftWin32/Views and Controls/Label.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public class Label: Control {
2626
public var text: String? {
2727
get {
2828
let szLength: Int32 = GetWindowTextLengthW(self.hWnd_)
29+
guard szLength > 0 else { return nil }
30+
2931
let buffer: [WCHAR] = Array<WCHAR>(unsafeUninitializedCapacity: Int(szLength) + 1) {
30-
$1 = Int(GetWindowTextW(self.hWnd_, $0.baseAddress!, CInt($0.count)))
32+
$1 = Int(GetWindowTextW(self.hWnd_, $0.baseAddress!, CInt($0.count))) + 1
3133
}
3234
return String(decodingCString: buffer, as: UTF16.self)
3335
}

0 commit comments

Comments
 (0)