Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20ccb06a authored by Elliott Hughes's avatar Elliott Hughes Committed by Android (Google) Code Review
Browse files

Merge "Fix Parcel.writeNative to not ignore 'offset'."

parents 059d5aff a28b83ee
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -356,7 +357,7 @@ public final class Parcel {
    public final native void enforceInterface(String interfaceName);

    /**
     * Write a byte array into the parcel at the current {#link #dataPosition},
     * Write a byte array into the parcel at the current {@link #dataPosition},
     * growing {@link #dataCapacity} if needed.
     * @param b Bytes to place into the parcel.
     */
@@ -365,7 +366,7 @@ public final class Parcel {
    }

    /**
     * Write an byte array into the parcel at the current {#link #dataPosition},
     * Write an byte array into the parcel at the current {@link #dataPosition},
     * growing {@link #dataCapacity} if needed.
     * @param b Bytes to place into the parcel.
     * @param offset Index of first byte to be written.
@@ -376,9 +377,7 @@ public final class Parcel {
            writeInt(-1);
            return;
        }
        if (b.length < offset + len || len < 0 || offset < 0) {
            throw new ArrayIndexOutOfBoundsException();
        }
        Arrays.checkOffsetAndCount(b.length, offset, len);
        writeNative(b, offset, len);
    }

+2 −4
Original line number Diff line number Diff line
@@ -1250,15 +1250,13 @@ static void android_os_Parcel_writeNative(JNIEnv* env, jobject clazz,
    if (parcel == NULL) {
        return;
    }
    void *dest;

    const status_t err = parcel->writeInt32(length);
    if (err != NO_ERROR) {
        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
    }

    dest = parcel->writeInplace(length);

    void* dest = parcel->writeInplace(length);
    if (dest == NULL) {
        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
        return;
@@ -1266,7 +1264,7 @@ static void android_os_Parcel_writeNative(JNIEnv* env, jobject clazz,

    jbyte* ar = (jbyte*)env->GetPrimitiveArrayCritical((jarray)data, 0);
    if (ar) {
        memcpy(dest, ar, length);
        memcpy(dest, ar + offset, length);
        env->ReleasePrimitiveArrayCritical((jarray)data, ar, 0);
    }
}