Skip to content

Commit e27b2b0

Browse files
committed
Account for nullability issues of bytes in NSData subclasses and return a placeholder value for now
1 parent bdafb2d commit e27b2b0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,14 @@ internal class _NSSwiftData : NSData {
815815
}
816816

817817
override var bytes: UnsafeRawPointer {
818-
return _backing.bytes!
818+
// NSData's byte pointer methods are not annotated for nullability correctly
819+
// (but assume non-null by the wrapping macro guards). This placeholder value
820+
// is to work-around this bug. Any indirection to the underlying bytes of a NSData
821+
// with a length of zero would have been a programmer error anyhow so the actual
822+
// return value here is not needed to be an allocated value. This is specifically
823+
// needed to live like this to be source compatible with Swift3. Beyond that point
824+
// this API may be subject to correction.
825+
return _backing.bytes ?? UnsafeRawPointer(bitPattern: 0xBAD0)!
819826
}
820827

821828
override func copy(with zone: NSZone? = nil) -> Any {

0 commit comments

Comments
 (0)