Skip to content

Commit

Permalink
Fix ByteIterator#indexWhere (#1285)
Browse files Browse the repository at this point in the history
It would blow up when from was out of bounds.
  • Loading branch information
JD557 authored Apr 16, 2024
1 parent a324eee commit 92d3f83
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,11 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
likeVector(a) { _.indexWhere(_ == b) }
}
}
"calling indexWhere(p, idx)" in {
check { (a: ByteString, b: Byte, idx: Int) =>
likeVector(a) { _.indexWhere(_ == b, math.max(0, idx)) }
}
}
"calling indexOf" in {
check { (a: ByteString, b: Byte) =>
likeVector(a) { _.indexOf(b) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] {
override def indexWhere(p: Byte => Boolean): Int = indexWhere(p, 0)
override def indexWhere(p: Byte => Boolean, from: Int): Int = {
var index = 0
while (index < from) {
while (index < from && hasNext) {
next()
index += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] {

override def indexWhere(p: Byte => Boolean, from: Int = 0): Int = {
var index = 0
while (index < from) {
while (index < from && hasNext) {
next()
index += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ abstract class ByteIterator extends BufferedIterator[Byte] {

override def indexWhere(p: Byte => Boolean, from: Int = 0): Int = {
var index = 0
while (index < from) {
while (index < from && hasNext) {
next()
index += 1
}
Expand Down

0 comments on commit 92d3f83

Please sign in to comment.