diff options
author | Elliott Hughes <enh@google.com> | 2009-11-03 15:52:10 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-11-03 15:52:10 -0800 |
commit | b7bfb47e9720ecc6e10f43878f27e40542a9c800 (patch) | |
tree | 27e5dbbe6c2d4aa95b4d5a3e17b5d68200c309ec /icu/src/main/java | |
parent | 538eac4977156a74e8a055d793097256efa0fba4 (diff) | |
download | libcore-b7bfb47e9720ecc6e10f43878f27e40542a9c800.zip libcore-b7bfb47e9720ecc6e10f43878f27e40542a9c800.tar.gz libcore-b7bfb47e9720ecc6e10f43878f27e40542a9c800.tar.bz2 |
CharsetDecoderICU/CharsetEncoderICU should take arrayOffset into account.
CharsetDecoderICU and CharsetEncoderICU special-case array-backed ByteBuffers
and CharBuffers for performance reasons, but they shouldn't assume that the
backing array always has offset 0.
An external user hit this while using the jAudioTagger library.
Test cases from user submission:
http://code.google.com/p/android/issues/detail?id=4237
See also: 2234697
Diffstat (limited to 'icu/src/main/java')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java | 16 | ||||
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java | 16 |
2 files changed, 22 insertions, 10 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java index 919d865..9c74d68 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java @@ -286,9 +286,11 @@ public final class CharsetDecoderICU extends CharsetDecoder{ private final int getArray(CharBuffer out){ if(out.hasArray()){ + // BEGIN android-changed: take arrayOffset into account output = out.array(); - outEnd = out.limit(); - return out.position(); + outEnd = out.arrayOffset() + out.limit(); + return out.arrayOffset() + out.position(); + // END android-changed }else{ outEnd = out.remaining(); // BEGIN android-added @@ -306,9 +308,11 @@ public final class CharsetDecoderICU extends CharsetDecoder{ } private final int getArray(ByteBuffer in){ if(in.hasArray()){ + // BEGIN android-changed: take arrayOffset into account input = in.array(); - inEnd = in.limit(); - return in.position()+savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/ + inEnd = in.arrayOffset() + in.limit(); + return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/ + // END android-changed }else{ inEnd = in.remaining(); // BEGIN android-added @@ -331,7 +335,9 @@ public final class CharsetDecoderICU extends CharsetDecoder{ } private final void setPosition(CharBuffer out){ if(out.hasArray()){ - out.position(out.position() + data[OUTPUT_OFFSET]); + // BEGIN android-changed: take arrayOffset into account + out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset()); + // END android-changed }else{ out.put(output,0,data[OUTPUT_OFFSET]); } diff --git a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java index ec169f4..eada080 100644 --- a/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java +++ b/icu/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java @@ -328,9 +328,11 @@ public final class CharsetEncoderICU extends CharsetEncoder { //------------------------------------------ private final int getArray(ByteBuffer out) { if(out.hasArray()){ + // BEGIN android-changed: take arrayOffset into account output = out.array(); - outEnd = out.limit(); - return out.position(); + outEnd = out.arrayOffset() + out.limit(); + return out.arrayOffset() + out.position(); + // END android-changed }else{ outEnd = out.remaining(); // BEGIN android-added @@ -348,9 +350,11 @@ public final class CharsetEncoderICU extends CharsetEncoder { private final int getArray(CharBuffer in) { if(in.hasArray()){ + // BEGIN android-changed: take arrayOffset into account input = in.array(); - inEnd = in.limit(); - return in.position()+savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/ + inEnd = in.arrayOffset() + in.limit(); + return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/ + // END android-changed }else{ inEnd = in.remaining(); // BEGIN android-added @@ -378,7 +382,9 @@ public final class CharsetEncoderICU extends CharsetEncoder { // array backing the buffer directly and wrote to // it, so just just set the position and return. // This is done to avoid the creation of temp array. - out.position(out.position() + data[OUTPUT_OFFSET] ); + // BEGIN android-changed: take arrayOffset into account + out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset()); + // END android-changed } else { out.put(output, 0, data[OUTPUT_OFFSET]); } |