You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by he...@apache.org on 2024/04/16 02:41:26 UTC
(pekko) branch main updated: chore: Fix ByteIterator#indexWhere (#1282)
This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new f70c26087c chore: Fix ByteIterator#indexWhere (#1282)
f70c26087c is described below
commit f70c26087c06c177051418597ee3bb10d6d5a4e6
Author: João Costa <jd...@gmail.com>
AuthorDate: Tue Apr 16 03:41:21 2024 +0100
chore: Fix ByteIterator#indexWhere (#1282)
It would blow up when from was out of bounds.
---
.../src/test/scala/org/apache/pekko/util/ByteStringSpec.scala | 5 +++++
actor/src/main/scala-2.12/org/apache/pekko/util/ByteIterator.scala | 2 +-
actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala | 2 +-
actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala | 2 +-
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala
index d723350759..aca2f242ed 100644
--- a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala
+++ b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala
@@ -923,6 +923,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) }
diff --git a/actor/src/main/scala-2.12/org/apache/pekko/util/ByteIterator.scala b/actor/src/main/scala-2.12/org/apache/pekko/util/ByteIterator.scala
index 46d50e2e6c..03c536d555 100644
--- a/actor/src/main/scala-2.12/org/apache/pekko/util/ByteIterator.scala
+++ b/actor/src/main/scala-2.12/org/apache/pekko/util/ByteIterator.scala
@@ -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
}
diff --git a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala
index af64128e65..412ae84c09 100644
--- a/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala
+++ b/actor/src/main/scala-2.13/org/apache/pekko/util/ByteIterator.scala
@@ -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
}
diff --git a/actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala b/actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala
index 85699fcca7..42d1d83e6a 100644
--- a/actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala
+++ b/actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala
@@ -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
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org