diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t6827.check | 12 | ||||
-rw-r--r-- | test/files/run/t6827.scala | 20 |
2 files changed, 26 insertions, 6 deletions
diff --git a/test/files/run/t6827.check b/test/files/run/t6827.check index 3a3a71c67d..4889e05be8 100644 --- a/test/files/run/t6827.check +++ b/test/files/run/t6827.check @@ -1,6 +1,6 @@ -start at -5: java.lang.IllegalArgumentException: requirement failed: start -5 out of range 10 -start at -1: java.lang.IllegalArgumentException: requirement failed: start -1 out of range 10 -start at limit: java.lang.IllegalArgumentException: requirement failed: start 10 out of range 10 +start at -5: java.lang.ArrayIndexOutOfBoundsException: -5 +start at -1: java.lang.ArrayIndexOutOfBoundsException: -1 +start at limit: ok start at limit-1: ok first 10: ok read all: ok @@ -8,8 +8,8 @@ test huge len: ok 5 from 5: ok 20 from 5: ok test len overflow: ok -start beyond limit: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 +start beyond limit: ok read 0: ok read -1: ok -invalid read 0: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 -invalid read -1: java.lang.IllegalArgumentException: requirement failed: start 30 out of range 10 +invalid read 0: ok +invalid read -1: ok diff --git a/test/files/run/t6827.scala b/test/files/run/t6827.scala index 8e17af09e2..eb020711bb 100644 --- a/test/files/run/t6827.scala +++ b/test/files/run/t6827.scala @@ -31,4 +31,24 @@ object Test extends App { // okay, see SI-7128 "...".toIterator.copyToArray(new Array[Char](0), 0, 0) + + + // Bonus test from @som-snytt to check for overflow in + // index calculations. + def testOverflow(start: Int, len: Int, expected: List[Char]) { + def copyFromIterator = { + val arr = Array.fill[Char](3)('-') + "abc".toIterator.copyToArray(arr, start, len) + arr.toList + } + def copyFromArray = { + val arr = Array.fill[Char](3)('-') + "abc".toArray.copyToArray(arr, start, len) + arr.toList + } + assert(copyFromIterator == expected) + assert(copyFromArray == expected) + } + testOverflow(1, Int.MaxValue - 1, "-ab".toList) + testOverflow(1, Int.MaxValue, "-ab".toList) } |