Skip to content

Commit

Permalink
Fixed an issue where a max bytes size of 0 could incorrectly read fro…
Browse files Browse the repository at this point in the history
…m the stream
  • Loading branch information
dimitribouniol committed Nov 18, 2021
1 parent e3bd4c0 commit 1d54822
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/Bytes/AsyncBytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extension AsyncIteratorProtocol where Element == Byte {
) async throws -> Bytes {
precondition(minCount <= maxCount, "maxCount must be larger than or equal to minCount")
precondition(minCount >= 0, "minCount must be larger than 0")
guard maxCount > 0 else { return [] }

var result = Bytes()
result.reserveCapacity(minCount)

Expand Down Expand Up @@ -72,6 +74,8 @@ extension AsyncIteratorProtocol where Element == Byte {
max maxCount: Int
) async rethrows -> Bytes {
precondition(maxCount >= 0, "maxCount must be larger than 0")
guard maxCount > 0 else { return [] }

var result = Bytes()
result.reserveCapacity(maxCount)

Expand Down Expand Up @@ -118,6 +122,8 @@ extension AsyncIteratorProtocol where Element == Byte {
) async throws -> Bytes? {
precondition(minCount <= maxCount, "maxCount must be larger than or equal to minCount")
precondition(minCount >= 0, "minCount must be larger than 0")
guard maxCount > 0 else { return [] }

var result = Bytes()
result.reserveCapacity(minCount)

Expand Down Expand Up @@ -149,7 +155,9 @@ extension AsyncIteratorProtocol where Element == Byte {
bytes type: Bytes.Type,
max maxCount: Int
) async rethrows -> Bytes? {
precondition(maxCount > 0, "maxCount must be larger than 0")
precondition(maxCount >= 0, "maxCount must be larger than 0")
guard maxCount > 0 else { return [] }

var result = Bytes()
result.reserveCapacity(maxCount)

Expand Down

0 comments on commit 1d54822

Please sign in to comment.