Skip to content

Commit cec2156

Browse files
committed
Fix CFSwiftStringGetBytes on big endian
1 parent a33dfb5 commit cec2156

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Foundation/NSCFString.swift

+5
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncodin
168168
for idx in 0..<range.length {
169169
// Since character is 2 bytes but the buffer is in term of 1 byte values, we have to split it up
170170
let character = encodingView[start.advanced(by: idx + range.location)]
171+
#if _endian(big)
172+
let byte0 = UInt8((character >> 8) & 0x00ff)
173+
let byte1 = UInt8(character & 0x00ff)
174+
#else
171175
let byte0 = UInt8(character & 0x00ff)
172176
let byte1 = UInt8((character >> 8) & 0x00ff)
177+
#endif
173178
buffer.advanced(by: idx * 2).initialize(to: byte0)
174179
buffer.advanced(by: (idx * 2) + 1).initialize(to: byte1)
175180
}

0 commit comments

Comments
 (0)