summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ashok Bhat <ashok.bhat@arm.com> 2014-03-05 12:40:53 +0000
committer Narayan Kamath <narayan@google.com> 2014-03-17 10:13:16 +0000
commit2bb39d7a43fdb28ecdafd65ea4b89dc05c1ad7be (patch)
tree6ffa4ae2224a39de274c4aa72a28ed74e775e557
parentd93e7b2424b7ab442065b0d9cecb8b72a9c5c8ed (diff)
Pass int32_t for JNI calls to java Input/Output streams.
Passing size_t is problematic on 64 bit platforms where it's 8 bytes in size. Conversion to int32_t is safe because the size argument is always clamped to fCapacity, which is 4 bytes wide. Signed-off-by: Ashok Bhat <ashok.bhat@arm.com> Change-Id: I58558561a4f56451485f1a5fc6cdeda677247071
-rw-r--r--core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp
index da8f083059eb..2cb101515586 100644
--- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp
+++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp
@@ -63,9 +63,14 @@ private:
size_t bytesRead = 0;
// read the bytes
do {
- size_t requested = size;
- if (requested > fCapacity)
+ jint requested = 0;
+ if (size > static_cast<size_t>(fCapacity)) {
requested = fCapacity;
+ } else {
+ // This is safe because requested is clamped to (jint)
+ // fCapacity.
+ requested = static_cast<jint>(size);
+ }
jint n = env->CallIntMethod(fJavaInputStream,
gInputStream_readMethodID, fJavaByteArray, 0, requested);
@@ -120,7 +125,7 @@ private:
JNIEnv* fEnv;
jobject fJavaInputStream; // the caller owns this object
jbyteArray fJavaByteArray; // the caller owns this object
- size_t fCapacity;
+ jint fCapacity;
size_t fBytesRead;
bool fIsAtEnd;
};
@@ -174,14 +179,18 @@ public:
fCapacity = env->GetArrayLength(storage);
}
- virtual bool write(const void* buffer, size_t size) {
+ virtual bool write(const void* buffer, size_t size) {
JNIEnv* env = fEnv;
jbyteArray storage = fJavaByteArray;
while (size > 0) {
- size_t requested = size;
- if (requested > fCapacity) {
+ jint requested = 0;
+ if (size > static_cast<size_t>(fCapacity)) {
requested = fCapacity;
+ } else {
+ // This is safe because requested is clamped to (jint)
+ // fCapacity.
+ requested = static_cast<jint>(size);
}
env->SetByteArrayRegion(storage, 0, requested,
@@ -216,7 +225,7 @@ private:
JNIEnv* fEnv;
jobject fJavaOutputStream; // the caller owns this object
jbyteArray fJavaByteArray; // the caller owns this object
- size_t fCapacity;
+ jint fCapacity;
};
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream,