Skip to content

Commit

Permalink
Fix NPE caused by high index (zio#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilu committed May 26, 2019
1 parent 1a4e7e4 commit 28159aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -32,7 +32,7 @@ private[zio] final class StackBool private () {
var ie = ((64L - i0) + index) >> 6
var cur = head

while (ie > 0) {
while (ie > 0 && (cur ne null)) {
ie -= 1
cur = cur.next
}
Expand Down
Expand Up @@ -10,6 +10,7 @@ class StackBoolSpec extends Specification with ScalaCheck {
From/to list identity $e1
Push/pop example $e2
Peek/pop identity $e3
GetOrElse index out of bounds $e4
"""

import Arbitrary._
Expand Down Expand Up @@ -53,6 +54,12 @@ class StackBoolSpec extends Specification with ScalaCheck {
}
}

def e4 = {
val stack = StackBool()
val result = stack.getOrElse(100, true)
result must_=== true
}

private def boolListGen(min: Int, max: Int) =
for {
size <- Gen.choose(min, max)
Expand Down

0 comments on commit 28159aa

Please sign in to comment.