Skip to content

Commit 1cc64e1

Browse files
committed
Review comments.
1 parent a99a79d commit 1cc64e1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/swift/Data.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public struct DispatchData : RandomAccessCollection {
7272
///
7373
/// - parameter bytes: A buffer pointer containing the data.
7474
/// - 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")
7676
public init(bytesNoCopy bytes: UnsafeBufferPointer<UInt8>, deallocator: Deallocator = .free) {
7777
let (q, b) = deallocator._deallocator
7878
let d = bytes.baseAddress == nil ? _swift_dispatch_data_empty()
@@ -200,10 +200,11 @@ public struct DispatchData : RandomAccessCollection {
200200

201201
/// Copy the contents of the data to a pointer.
202202
///
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.
204205
/// - 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.
206206
public func copyBytes(to pointer: UnsafeMutableRawBufferPointer, count: Int) {
207+
assert(count <= pointer.count, "Buffer too small to copy \(count) bytes")
207208
guard pointer.baseAddress != nil else { return }
208209
_copyBytesHelper(to: pointer.baseAddress!, from: 0..<count)
209210
}
@@ -220,10 +221,11 @@ public struct DispatchData : RandomAccessCollection {
220221

221222
/// Copy a subset of the contents of the data to a pointer.
222223
///
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.
224226
/// - 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.
226227
public func copyBytes(to pointer: UnsafeMutableRawBufferPointer, from range: CountableRange<Index>) {
228+
assert(range.count <= pointer.count, "Buffer too small to copy \(range.count) bytes")
227229
guard pointer.baseAddress != nil else { return }
228230
_copyBytesHelper(to: pointer.baseAddress!, from: range)
229231
}

0 commit comments

Comments
 (0)