Skip to content

Commit 52ceff1

Browse files
authored
Merge pull request #2 from p-x9/fix/tuple-to-string-swift6
Fix conversion of char tuple to string
2 parents eda546f + b00ab39 commit 52ceff1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/ELFKit/Extension/String+.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ extension String {
1212
typealias UInt8Tuple16 = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
1313

1414
init(tuple: UInt8Tuple16) {
15-
var buffer = tuple
16-
self = withUnsafePointer(to: &buffer.0) {
17-
let data = Data(bytes: $0, count: 16) + [0]
18-
return String(cString: data)!
15+
self = withUnsafePointer(to: tuple) {
16+
let size = MemoryLayout<UInt8Tuple16>.size
17+
let data = Data(bytes: $0, count: size) + [0]
18+
return String(cString: data) ?? ""
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)