diff options
| author | Jesse Wilson <jessewilson@google.com> | 2009-07-30 09:56:34 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2009-07-30 09:56:34 -0700 |
| commit | 4181e0fcd5383eadf9cddadf3230fab383782ca0 (patch) | |
| tree | 7c08350b4c162f0f3358aaad4869d4d7bee892b2 | |
| parent | 451ee2cdd4bce45cea6020409ea1f2ebd11eea71 (diff) | |
| parent | a2ef9a8dc12d949639c62eab7e5acc88080e059d (diff) | |
| download | libcore-4181e0fcd5383eadf9cddadf3230fab383782ca0.zip libcore-4181e0fcd5383eadf9cddadf3230fab383782ca0.tar.gz libcore-4181e0fcd5383eadf9cddadf3230fab383782ca0.tar.bz2 | |
am bd79e449: Fix an issue where we\'re adding 4x the intended offset.
Merge commit 'bd79e4498465381117f2cbc6399a256061f1d144'
* commit 'bd79e4498465381117f2cbc6399a256061f1d144':
Fix an issue where we're adding 4x the intended offset.
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 3f7b0b1..3e31743 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 @@ -218,7 +218,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); } @@ -232,7 +232,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; @@ -241,7 +241,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.", |
