@@ -72,7 +72,7 @@ public struct DispatchData : RandomAccessCollection {
72
72
///
73
73
/// - parameter bytes: A buffer pointer containing the data.
74
74
/// - parameter deallocator: Specifies the mechanism to free the indicated buffer.
75
- @available ( swift, deprecated: 4 , message: " Use init(bytes : UnsafeRawBufferPointer, deallocater: Deallocator) instead " )
75
+ @available ( swift, deprecated: 4 , message: " Use init(bytesNoCopy : UnsafeRawBufferPointer, deallocater: Deallocator) instead " )
76
76
public init ( bytesNoCopy bytes: UnsafeBufferPointer < UInt8 > , deallocator: Deallocator = . free) {
77
77
let ( q, b) = deallocator. _deallocator
78
78
let d = bytes. baseAddress == nil ? _swift_dispatch_data_empty ( )
@@ -200,10 +200,11 @@ public struct DispatchData : RandomAccessCollection {
200
200
201
201
/// Copy the contents of the data to a pointer.
202
202
///
203
- /// - parameter pointer: A pointer to the buffer you wish to copy the bytes into.
203
+ /// - parameter pointer: A pointer to the buffer you wish to copy the bytes into. The buffer must be large
204
+ /// enough to hold `count` bytes.
204
205
/// - parameter count: The number of bytes to copy.
205
- /// - warning: This method does not verify that the contents at pointer have enough space to hold `count` bytes.
206
206
public func copyBytes( to pointer: UnsafeMutableRawBufferPointer , count: Int ) {
207
+ assert ( count <= pointer. count, " Buffer too small to copy \( count) bytes " )
207
208
guard pointer. baseAddress != nil else { return }
208
209
_copyBytesHelper ( to: pointer. baseAddress!, from: 0 ..< count)
209
210
}
@@ -220,10 +221,11 @@ public struct DispatchData : RandomAccessCollection {
220
221
221
222
/// Copy a subset of the contents of the data to a pointer.
222
223
///
223
- /// - parameter pointer: A pointer to the buffer you wish to copy the bytes into.
224
+ /// - parameter pointer: A pointer to the buffer you wish to copy the bytes into. The buffer must be large
225
+ /// enough to hold `count` bytes.
224
226
/// - parameter range: The range in the `Data` to copy.
225
- /// - warning: This method does not verify that the contents at pointer have enough space to hold the required number of bytes.
226
227
public func copyBytes( to pointer: UnsafeMutableRawBufferPointer , from range: CountableRange < Index > ) {
228
+ assert ( range. count <= pointer. count, " Buffer too small to copy \( range. count) bytes " )
227
229
guard pointer. baseAddress != nil else { return }
228
230
_copyBytesHelper ( to: pointer. baseAddress!, from: range)
229
231
}
0 commit comments