File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -42,13 +42,14 @@ extension XMLParser {
42
42
}
43
43
44
44
private func UTF8STRING( _ bytes: UnsafePointer < UInt8 > ? ) -> String ? {
45
- guard let bytes = bytes else { return nil }
46
- // strlen operates on the wrong type, char*. We can't rebind the memory to a different type without knowing its length,
47
- // but since we know strlen is in libc, it's safe to directly bitcast the pointer without worrying about multiple accesses
48
- // of different types visible to the compiler.
49
- let len = strlen ( unsafeBitCast ( bytes, to: UnsafePointer< Int8> . self ) )
50
- let str = String . _fromCodeUnitSequence ( UTF8 . self, input: UnsafeBufferPointer ( start: bytes, count: Int ( len) ) )
51
- return str
45
+ guard let bytes = bytes else {
46
+ return nil
47
+ }
48
+ if let ( str, _) = String . decodeCString ( bytes, as: UTF8 . self,
49
+ repairingInvalidCodeUnits: false ) {
50
+ return str
51
+ }
52
+ return nil
52
53
}
53
54
54
55
internal func _NSXMLParserCurrentParser( ) -> _CFXMLInterface ? {
You can’t perform that action at this time.
0 commit comments