summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2009-07-28 16:49:40 -0700
committerJesse Wilson <jessewilson@google.com>2009-07-29 15:00:09 -0700
commita2ef9a8dc12d949639c62eab7e5acc88080e059d (patch)
tree40610f79027308c8ab85fbd4e9e80a2d4646f3cf
parent87eb4de6347e1be029cde77dd43ad9b1af901472 (diff)
downloadlibcore-a2ef9a8dc12d949639c62eab7e5acc88080e059d.zip
libcore-a2ef9a8dc12d949639c62eab7e5acc88080e059d.tar.gz
libcore-a2ef9a8dc12d949639c62eab7e5acc88080e059d.tar.bz2
Fix an issue where we're adding 4x the intended offset.
We were doing pointer arithmetic of mixed types (jint* and jint), and the type conversion ended up causing the offset to be converted an extra time.
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp6
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java25
-rw-r--r--nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java25
3 files changed, 53 insertions, 3 deletions
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
index 5bd7907..c5e92bb 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
@@ -184,7 +184,7 @@ static void harmony_nio_putShortsImpl(JNIEnv *_env, jobject _this,
if (swap) {
swapShorts(src_ + offset, length);
}
- memcpy((jbyte *)pointer, src_ + offset, length);
+ memcpy((jbyte *)pointer, (jbyte *)src_ + offset, length);
if (swap) {
swapShorts(src_ + offset, length);
}
@@ -198,7 +198,7 @@ static void harmony_nio_putShortsImpl(JNIEnv *_env, jobject _this,
*/
static void harmony_nio_putIntsImpl(JNIEnv *_env, jobject _this,
jint pointer, jintArray src, jint offset, jint length, jboolean swap) {
-
+
offset = offset << 2;
length = length << 2;
@@ -207,7 +207,7 @@ static void harmony_nio_putIntsImpl(JNIEnv *_env, jobject _this,
if (swap) {
swapInts(src_ + offset, length);
}
- memcpy((jbyte *)pointer, src_ + offset, length);
+ memcpy((jbyte *)pointer, (jbyte *)src_ + offset, length);
if (swap) {
swapInts(src_ + offset, length);
}
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
index 489d265..5227d47 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
@@ -22,6 +22,7 @@ import dalvik.annotation.TestTargetClass;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.IntBuffer;
@TestTargetClass(java.nio.IntBuffer.class)
public class DirectIntBufferTest extends IntBufferTest {
@@ -37,6 +38,30 @@ public class DirectIntBufferTest extends IntBufferTest {
baseBuf = null;
}
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "put",
+ args = {int[].class, int.class, int.class}
+ )
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ IntBuffer intBuffer = byteBuffer.asIntBuffer();
+
+ int[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ intBuffer.put(source, 2, 2);
+ intBuffer.put(source, 4, 2);
+ assertEquals(4, intBuffer.get(0));
+ assertEquals(5, intBuffer.get(1));
+ assertEquals(6, intBuffer.get(2));
+ assertEquals(7, intBuffer.get(3));
+ }
+
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies hasArray method for direct IntBuffer.",
diff --git a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
index a6e922b..91762a7 100644
--- a/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
+++ b/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
@@ -23,6 +23,7 @@ import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
+import java.nio.IntBuffer;
@TestTargetClass(java.nio.ShortBuffer.class)
public class DirectShortBufferTest extends ShortBufferTest {
@@ -38,6 +39,30 @@ public class DirectShortBufferTest extends ShortBufferTest {
baseBuf = null;
}
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "put",
+ args = {short[].class, int.class, int.class}
+ )
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
+
+ short[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ shortBuffer.put(source, 2, 2);
+ shortBuffer.put(source, 4, 2);
+ assertEquals(4, shortBuffer.get(0));
+ assertEquals(5, shortBuffer.get(1));
+ assertEquals(6, shortBuffer.get(2));
+ assertEquals(7, shortBuffer.get(3));
+ }
+
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies hasArray method for direct ShortBuffer.",