@@ -45,8 +45,9 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
45
45
/// - parameter bytes: A pointer to the memory. It will be copied.
46
46
/// - parameter count: The number of bytes to copy.
47
47
public init ( bytes buffer: UnsafeBufferPointer < UInt8 > ) {
48
- __wrapped = _swift_dispatch_data_create (
49
- buffer. baseAddress!, buffer. count, nil , _swift_dispatch_data_destructor_default ( ) ) as! __DispatchData
48
+ __wrapped = buffer. baseAddress == nil ? _swift_dispatch_data_empty ( )
49
+ : _swift_dispatch_data_create ( buffer. baseAddress!, buffer. count, nil ,
50
+ _swift_dispatch_data_destructor_default ( ) ) as! __DispatchData
50
51
}
51
52
52
53
/// Initialize a `Data` without copying the bytes.
@@ -56,9 +57,8 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
56
57
/// - parameter deallocator: Specifies the mechanism to free the indicated buffer.
57
58
public init ( bytesNoCopy bytes: UnsafeBufferPointer < UInt8 > , deallocator: Deallocator = . free) {
58
59
let ( q, b) = deallocator. _deallocator
59
-
60
- __wrapped = _swift_dispatch_data_create (
61
- bytes. baseAddress!, bytes. count, q, b) as! __DispatchData
60
+ __wrapped = bytes. baseAddress == nil ? _swift_dispatch_data_empty ( )
61
+ : _swift_dispatch_data_create ( bytes. baseAddress!, bytes. count, q, b) as! __DispatchData
62
62
}
63
63
64
64
internal init ( data: __DispatchData ) {
0 commit comments