You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/07/07 22:31:19 UTC
svn commit: r419972 - in
/incubator/harmony/enhanced/classlib/trunk/modules/nio/src:
main/java/java/nio/DirectByteBuffer.java
main/java/java/nio/ReadWriteDirectByteBuffer.java
test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
Author: tellison
Date: Fri Jul 7 13:31:19 2006
New Revision: 419972
URL: http://svn.apache.org/viewvc?rev=419972&view=rev
Log:
Fix for HARMONY-794 ([classlib][nio]Harmony crashes on java.nio.ByteBuffer.getDouble(Integer.MAX_VALUE) instead of throwing IndexOutOfBoundateException)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java?rev=419972&r1=419971&r2=419972&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java Fri Jul 7 13:31:19 2006
@@ -77,7 +77,7 @@
* @see java.nio.ByteBuffer#get(byte[], int, int)
*/
public final ByteBuffer get(byte[] dest, int off, int len) {
- if ((off < 0 ) || (len < 0) || off + len > dest.length) {
+ if ((off < 0 ) || (len < 0) || (long)off + (long)len > dest.length) {
throw new IndexOutOfBoundsException();
}
if (len > remaining()) {
@@ -113,7 +113,7 @@
}
public final double getDouble(int index) {
- if (index < 0 || index + 8 > limit) {
+ if (index < 0 || (long)index + 8 > limit) {
throw new IndexOutOfBoundsException();
}
return getBaseAddress().getDouble(offset + index, order);
@@ -130,7 +130,7 @@
}
public final float getFloat(int index) {
- if (index < 0 || index + 4 > limit) {
+ if (index < 0 || (long)index + 4 > limit) {
throw new IndexOutOfBoundsException();
}
return getBaseAddress().getFloat(offset + index, order);
@@ -147,7 +147,7 @@
}
public final int getInt(int index) {
- if (index < 0 || index + 4 > limit) {
+ if (index < 0 || (long)index + 4 > limit) {
throw new IndexOutOfBoundsException();
}
return getBaseAddress().getInt(offset + index, order);
@@ -164,7 +164,7 @@
}
public final long getLong(int index) {
- if (index < 0 || index + 8 > limit) {
+ if (index < 0 || (long)index + 8 > limit) {
throw new IndexOutOfBoundsException();
}
return getBaseAddress().getLong(offset + index, order);
@@ -181,7 +181,7 @@
}
public final short getShort(int index) {
- if (index < 0 || index + 2 > limit) {
+ if (index < 0 || (long)index + 2 > limit) {
throw new IndexOutOfBoundsException();
}
return getBaseAddress().getShort(offset + index, order);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java?rev=419972&r1=419971&r2=419972&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java Fri Jul 7 13:31:19 2006
@@ -127,7 +127,7 @@
}
public ByteBuffer putDouble(int index, double value) {
- if (index < 0 || index + 8 > limit) {
+ if (index < 0 || (long)index + 8 > limit) {
throw new IndexOutOfBoundsException();
}
getBaseAddress().setDouble(offset + index, value, order);
@@ -145,7 +145,7 @@
}
public ByteBuffer putFloat(int index, float value) {
- if (index < 0 || index + 4 > limit) {
+ if (index < 0 || (long)index + 4 > limit) {
throw new IndexOutOfBoundsException();
}
getBaseAddress().setFloat(offset + index, value, order);
@@ -163,7 +163,7 @@
}
public ByteBuffer putInt(int index, int value) {
- if (index < 0 || index + 4 > limit) {
+ if (index < 0 || (long)index + 4 > limit) {
throw new IndexOutOfBoundsException();
}
getBaseAddress().setInt(offset + index, value, order);
@@ -181,7 +181,7 @@
}
public ByteBuffer putLong(int index, long value) {
- if (index < 0 || index + 8 > limit) {
+ if (index < 0 || (long)index + 8 > limit) {
throw new IndexOutOfBoundsException();
}
getBaseAddress().setLong(offset + index, value, order);
@@ -199,7 +199,7 @@
}
public ByteBuffer putShort(int index, short value) {
- if (index < 0 || index + 2 > limit) {
+ if (index < 0 || (long)index + 2 > limit) {
throw new IndexOutOfBoundsException();
}
getBaseAddress().setShort(offset + index, value, order);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java?rev=419972&r1=419971&r2=419972&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java Fri Jul 7 13:31:19 2006
@@ -1196,6 +1196,12 @@
}
buf.order(ByteOrder.BIG_ENDIAN);
+
+ try {
+ ByteBuffer.allocateDirect(16).putChar(Integer.MAX_VALUE, 'h');
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
}
public void testGetDouble() {
@@ -1259,6 +1265,12 @@
}
buf.order(ByteOrder.BIG_ENDIAN);
+
+ try {
+ ByteBuffer.allocateDirect(16).getDouble(Integer.MAX_VALUE);
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
}
public void testPutDouble() {
@@ -1539,6 +1551,11 @@
}
buf.order(ByteOrder.BIG_ENDIAN);
+ try {
+ ByteBuffer.allocateDirect(16).getInt(Integer.MAX_VALUE);
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
}
public void testPutInt() {