example/swift-vt-xcframework: fix buffer overflow

pull/12149/head
Mitchell Hashimoto 2026-04-06 14:50:35 -07:00
parent 9b281cde43
commit 249aee7010
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 3 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import Foundation
import GhosttyVt
// Create a terminal with a small grid
@ -38,7 +39,8 @@ guard allocResult == GHOSTTY_SUCCESS, let buf else {
}
print("Plain text (\(len) bytes):")
print(String(cString: buf))
let data = Data(bytes: buf, count: len)
print(String(data: data, encoding: .utf8) ?? "<invalid UTF-8>")
ghostty_free(nil, buf, len)
ghostty_formatter_free(formatter)