Skip to content

[Data] fix crash when creating iterator of empty DispatchData #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/swift/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,15 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
var ptr: UnsafePointer<Void>?
self._count = 0
self._data = CDispatch.dispatch_data_create_map(_data.__wrapped, &ptr, &self._count)
self._ptr = UnsafePointer(ptr!)
self._ptr = UnsafePointer(ptr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not also be accompanied by the type change on line 258?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it got lost. Back now.

self._position = _data.startIndex

// The only time we expect a 'nil' pointer is when the data is empty.
assert(self._ptr != nil || self._count == self._position)
}

/// Advance to the next element and return it, or `nil` if no next
/// element exists.
///
/// - Precondition: No preceding call to `self.next()` has returned `nil`.
public mutating func next() -> DispatchData._Element? {
if _position == _count { return nil }
let element = _ptr[_position];
Expand All @@ -254,7 +255,7 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
}

internal let _data: dispatch_data_t
internal var _ptr: UnsafePointer<UInt8>
internal var _ptr: UnsafePointer<UInt8>!
internal var _count: Int
internal var _position: DispatchData.Index
}
Expand Down