6888149: AtomicReferenceArray causes SIGSEGV -> SEGV_MAPERR error

Avoid integer overflow by using long arithmetic

Reviewed-by: martin, dholmes
This commit is contained in:
Doug Lea 2009-10-06 12:20:35 -07:00
parent c09da77c87
commit 9ae7ce5ffe
3 changed files with 3 additions and 3 deletions

View file

@ -57,7 +57,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
private long rawIndex(int i) { private long rawIndex(int i) {
if (i < 0 || i >= array.length) if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i); throw new IndexOutOfBoundsException("index " + i);
return base + i * scale; return base + (long) i * scale;
} }
/** /**

View file

@ -56,7 +56,7 @@ public class AtomicLongArray implements java.io.Serializable {
private long rawIndex(int i) { private long rawIndex(int i) {
if (i < 0 || i >= array.length) if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i); throw new IndexOutOfBoundsException("index " + i);
return base + i * scale; return base + (long) i * scale;
} }
/** /**

View file

@ -57,7 +57,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
private long rawIndex(int i) { private long rawIndex(int i) {
if (i < 0 || i >= array.length) if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i); throw new IndexOutOfBoundsException("index " + i);
return base + i * scale; return base + (long) i * scale;
} }
/** /**