Thursday, December 23, 2010

[android-developers] SensorService has a bug related to Integer array conversion from C to JAVA

Hello,

I got a special concern about sensor service and sensor manager of
Android.
Recently I am trying to implement the sensor hal, and I found
susficious code
inside of android_open().


static jobject
android_open(JNIEnv *env, jclass clazz)
{

~~~~~~~~
if (handle->numFds > 0) {
jobjectArray fdArray = env->NewObjectArray(handle->numFds,
gParcelFileDescriptorOffsets.mClass, NULL);

for (int i = 0; i < handle->numFds; i++) {
~~~~~~~~~~~~~~~~~~~~~~~~~~
}
// bundle.putParcelableArray("fds", fdArray);
env->CallVoidMethod(bundle,
gBundleOffsets.mPutParcelableArray,
env->NewStringUTF("fds"), fdArray);
}


if (handle->numInts > 0) {
jintArray intArray = env->NewIntArray(handle->numInts);

//@@@@@@@ WHY index is handle->numInts??? @@@@@@@
env->SetIntArrayRegion(intArray, 0, handle->numInts, &handle-
>data[handle->numInts]);

// bundle.putIntArray("ints", intArray);
env->CallVoidMethod(bundle, gBundleOffsets.mPutIntArray,
env->NewStringUTF("ints"), intArray);
}

// delete the file handle, but don't close any file descriptors
native_handle_delete(handle);
return bundle;
}

In this function, we want to copy fds array and then copy int arrays.
But in case of integer array, you need to focus on the start point of
data array.

You write code like

handle->data[handle->numInts]

I think It should be

handle->data[handle->numFds]);


You might have mistake of starting point of data array to copy Integer
data.

Pls check it.
Let me know that it is correct or not

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment