Skip to content

Commit e8fc886

Browse files
committed
Fix CFSwiftStringGetBytes on big endian
1 parent 1b4bb4e commit e8fc886

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
@@ -170,8 +170,13 @@ internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncodin
170170
let character = encodingView[start.advanced(by: idx + range.location)]
171171
let byte0 = UInt8(character & 0x00ff)
172172
let byte1 = UInt8((character >> 8) & 0x00ff)
173+
#if _endian(big)
174+
buffer.advanced(by: idx * 2).initialize(to: byte1)
175+
buffer.advanced(by: (idx * 2) + 1).initialize(to: byte0)
176+
#else
173177
buffer.advanced(by: idx * 2).initialize(to: byte0)
174178
buffer.advanced(by: (idx * 2) + 1).initialize(to: byte1)
179+
#endif
175180
}
176181
}
177182
// Every character was 2 bytes

0 commit comments

Comments
 (0)