Guard against overflow in fjbg. Closes #3671, no review.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@23033 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2010-09-19 03:58:11 +00:00
parent edf78d7483
commit c2298a9720
3 changed files with 11 additions and 3 deletions

Binary file not shown.

View File

@ -575,12 +575,13 @@ public class JExtendedCode extends JCode {
}
int keyMin = keys[0], keyMax = keys[keys.length - 1];
int keyRange = keyMax - keyMin + 1;
/** Calculate in long to guard against overflow. */
long keyRange = (long)keyMax - keyMin + 1;
if ((double)keys.length / (double)keyRange >= minDensity) {
// Keys are dense enough, use a table in which holes are
// filled with defaultBranch.
int[] newKeys = new int[keyRange];
Label[] newBranches = new Label[keyRange];
int[] newKeys = new int[(int)keyRange];
Label[] newBranches = new Label[(int)keyRange];
int oldPos = 0;
for (int i = 0; i < keyRange; ++i) {
int key = keyMin + i;

View File

@ -0,0 +1,7 @@
object Crash {
def crash(value: Int): Unit =
value match {
case java.lang.Integer.MAX_VALUE => println("MAX_VALUE")
case java.lang.Integer.MIN_VALUE => println("MIN_VALUE")
}
}