From e8c85a37186b65561a3826b9889c9d06a69650da Mon Sep 17 00:00:00 2001 From: Heejong Lee Date: Sat, 6 Apr 2013 01:48:31 +0900 Subject: SI-7080 improve boundary value checking for BitSet When BitSet accepts a very large integer such as Int.MaxValue, integer overflow possibly occurs in the calculation of boundary value "nwords * WordLength". This faulty boundary condition causes empty-iterator problem like following: scala> import collection.mutable.BitSet import collection.mutable.BitSet scala> val x = BitSet(Int.MaxValue) x: scala.collection.mutable.BitSet = BitSet() scala> x.iterator res0: Iterator[Int] = empty iterator --- test/files/run/bitsets.check | 4 ++++ test/files/run/bitsets.scala | 14 ++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'test/files') diff --git a/test/files/run/bitsets.check b/test/files/run/bitsets.check index 41c2ccdcb8..9bbc769b72 100644 --- a/test/files/run/bitsets.check +++ b/test/files/run/bitsets.check @@ -42,6 +42,10 @@ b2:BitSet(5) b3:BitSet(5, 7) b4:BitSet(7) b0:BitSet(5, 6, 7) +bMax:BitSet(2147483647) +2147483647 +bLarge:BitSet(2000000001) +false is0 = BitSet() is1 = BitSet() is2 = BitSet(2) diff --git a/test/files/run/bitsets.scala b/test/files/run/bitsets.scala index d55f9e4e83..c88782cab7 100644 --- a/test/files/run/bitsets.scala +++ b/test/files/run/bitsets.scala @@ -115,6 +115,19 @@ object TestMutable3 { println(s"b0:$b0") } +object TestMutable4 { + import scala.collection.mutable.BitSet + + val bMax = BitSet(Int.MaxValue) + println(s"bMax:$bMax") + bMax.foreach(println) + + val bLarge = BitSet(2000000001) + println(s"bLarge:$bLarge") + + println(bMax == bLarge) +} + object TestImmutable { import scala.collection.immutable.BitSet @@ -190,6 +203,7 @@ object Test extends App { TestMutable TestMutable2 TestMutable3 + TestMutable4 TestImmutable TestImmutable2 } -- cgit v1.2.3