Skip to content

Commit 0567483

Browse files
authored
Merge pull request #1498 from tid-kijyun/fix_access_to_memory_out_of_range
2 parents 1f62d19 + b56140a commit 0567483

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Foundation/NSString.swift

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC
294294
}
295295

296296
internal func _fastCStringContents(_ nullTerminated: Bool) -> UnsafePointer<Int8>? {
297+
guard !nullTerminated else {
298+
// There is no way to fastly and safely retrieve a pointer to a null-terminated string from a String of Swift.
299+
return nil
300+
}
297301
if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
298302
if _storage._guts._isContiguousASCII {
299303
return unsafeBitCast(_storage._core.startASCII, to: UnsafePointer<Int8>.self)

0 commit comments

Comments
 (0)