Skip to content

Commit 2c198bb

Browse files
author
Sergey Minakov
committed
fix for NSData.bytes crash
1 parent 56ac324 commit 2c198bb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Foundation/NSData.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
217217
}
218218

219219
open var bytes: UnsafeRawPointer {
220-
return UnsafeRawPointer(CFDataGetBytePtr(_cfObject))
220+
guard let bytes = CFDataGetBytePtr(_cfObject) else {
221+
//This could occure on empty data being encoded.
222+
return UnsafeRawPointer([])
223+
}
224+
return UnsafeRawPointer(bytes)
221225
}
222226

223227

Foundation/NSURLRequest.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ open class NSURLRequest : NSObject, NSSecureCoding, NSCopying, NSMutableCopying
216216
preconditionFailure("Unkeyed coding is unsupported.")
217217
}
218218

219-
self._body = .data(Data())
220-
221219
aCoder.encode(self.url?._bridgeToObjectiveC(), forKey: "NS.url")
222220
aCoder.encode(self._allHTTPHeaderFields?._bridgeToObjectiveC(), forKey: "NS._allHTTPHeaderFields")
223221
aCoder.encode(self.mainDocumentURL?._bridgeToObjectiveC(), forKey: "NS.mainDocumentURL")

0 commit comments

Comments
 (0)