Merge pull request #208 from ktopley-apple/dispatch-data-null-buffer

Fixes crash when DispatchData is created from an UnsafeBufferPointer<UInt8> with a nil address (Radar 29337927)
diff --git a/libkqueue b/libkqueue
index 1281e04..b3f81ec 160000
--- a/libkqueue
+++ b/libkqueue
@@ -1 +1 @@
-Subproject commit 1281e0460f086503d524b5cbaed603c771435376
+Subproject commit b3f81ecf680e826c2dc834316b5d77fc1be5a5c7
diff --git a/src/swift/Data.swift b/src/swift/Data.swift
index e0647e7..72f53d6 100644
--- a/src/swift/Data.swift
+++ b/src/swift/Data.swift
@@ -138,11 +138,16 @@
 
 	private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
 		var copiedCount = 0
+		if range.isEmpty { return }
+		let rangeSize = range.count
 		_ = CDispatch.dispatch_data_apply(__wrapped.__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafeRawPointer, size: Int) in
-			let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
-			memcpy(pointer + copiedCount, ptr, limit)
-			copiedCount += limit
-			return copiedCount < (range.endIndex - range.startIndex)
+			if offset >= range.endIndex { return false } // This region is after endIndex
+			let copyOffset = range.startIndex > offset ? range.startIndex - offset : 0 // offset of first byte, in this region
+			if copyOffset >= size { return true } // This region is before startIndex
+			let count = Swift.min(rangeSize - copiedCount, size - copyOffset)
+			memcpy(pointer + copiedCount, ptr + copyOffset, count)
+			copiedCount += count
+			return copiedCount < rangeSize
 		}
 	}
 
diff --git a/src/swift/Private.swift b/src/swift/Private.swift
index 8161416..3861b77 100644
--- a/src/swift/Private.swift
+++ b/src/swift/Private.swift
@@ -110,7 +110,7 @@
 	fatalError()
 }
 
-@available(*, unavailable, renamed:"DispatchQueue.asynchronously(self:group:qos:flags:execute:)")
+@available(*, unavailable, renamed:"DispatchQueue.async(self:group:qos:flags:execute:)")
 public func dispatch_group_async(_ group: DispatchGroup, _ queue: DispatchQueue, _ block: @escaping () -> Void)
 {
 	fatalError()
@@ -146,7 +146,7 @@
 	fatalError()
 }
 
-@available(*, unavailable, renamed:"DispatchQueue.asynchronously(self:execute:)")
+@available(*, unavailable, renamed:"DispatchQueue.async(self:execute:)")
 public func dispatch_async(_ queue: DispatchQueue, _ block: @escaping () -> Void)
 {
 	fatalError()