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 10:27:06 UTC
(pekko) branch 1.0.x updated: Fix ByteIterator#indexWhere (#1285)
This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch 1.0.x
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/1.0.x by this push:
new 92d3f83c95 Fix ByteIterator#indexWhere (#1285)
92d3f83c95 is described below
commit 92d3f83c958439374f3774de59ecbada2813c2a4
Author: João Costa <jd...@gmail.com>
AuthorDate: Tue Apr 16 11:27:01 2024 +0100
Fix ByteIterator#indexWhere (#1285)
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 46bd72c3cd..9e5fd8a4e2 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
@@ -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) }
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 150fa32af8..2a5ffe5990 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 5965345199..a5df292a26 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 c4eed52125..88069838db 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