More fixes to JNI error checking
* src/android.c (android_query_tree, android_get_geometry) (android_translate_coordinates, android_query_battery): Correctly handle result of GetTArrayElements. (android_exception_check_nonnull): New function. * src/android.h: * src/androidselect.c (Fandroid_get_clipboard): Likewise.
This commit is contained in:
parent
49d5aa3657
commit
f8a2619d98
3 changed files with 27 additions and 3 deletions
|
@ -4370,6 +4370,8 @@ android_query_tree (android_window handle, android_window *root_return,
|
|||
shorts
|
||||
= (*android_java_env)->GetShortArrayElements (android_java_env, array,
|
||||
NULL);
|
||||
android_exception_check_nonnull (shorts, array);
|
||||
|
||||
for (i = 1; i < nelements; ++i)
|
||||
children[i] = shorts[i];
|
||||
|
||||
|
@ -4422,6 +4424,7 @@ android_get_geometry (android_window handle,
|
|||
= (*android_java_env)->GetIntArrayElements (android_java_env,
|
||||
window_geometry,
|
||||
NULL);
|
||||
android_exception_check_nonnull (ints, window_geometry);
|
||||
|
||||
*x_return = ints[0];
|
||||
*y_return = ints[1];
|
||||
|
@ -4477,7 +4480,7 @@ android_translate_coordinates (android_window src, int x,
|
|||
/* Obtain the coordinates from the array. */
|
||||
ints = (*android_java_env)->GetIntArrayElements (android_java_env,
|
||||
coordinates, NULL);
|
||||
android_exception_check_1 (coordinates);
|
||||
android_exception_check_nonnull (ints, coordinates);
|
||||
|
||||
*root_x = ints[0];
|
||||
*root_y = ints[1];
|
||||
|
@ -5302,6 +5305,26 @@ android_exception_check_2 (jobject object, jobject object1)
|
|||
}
|
||||
}
|
||||
|
||||
/* Check for JNI problems based on the value of OBJECT.
|
||||
|
||||
Signal out of memory if OBJECT is NULL. OBJECT1 means the
|
||||
same as in `android_exception_check_1'.
|
||||
|
||||
This function is useful when checking for errors from JNI
|
||||
functions that do not set exceptions on failure, such as
|
||||
`GetIntArrayElements'. */
|
||||
|
||||
void
|
||||
android_exception_check_nonnull (void *object, jobject object1)
|
||||
{
|
||||
if (object)
|
||||
return;
|
||||
|
||||
if (object1)
|
||||
ANDROID_DELETE_LOCAL_REF (object1);
|
||||
|
||||
memory_full (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -5656,7 +5679,7 @@ android_query_battery (struct android_battery_state *status)
|
|||
|
||||
longs = (*android_java_env)->GetLongArrayElements (android_java_env,
|
||||
array, NULL);
|
||||
android_exception_check_1 (array);
|
||||
android_exception_check_nonnull (longs, array);
|
||||
|
||||
status->capacity = longs[0];
|
||||
status->charge_counter = longs[1];
|
||||
|
|
|
@ -86,6 +86,7 @@ extern jstring android_build_jstring (const char *);
|
|||
extern void android_exception_check (void);
|
||||
extern void android_exception_check_1 (jobject);
|
||||
extern void android_exception_check_2 (jobject, jobject);
|
||||
extern void android_exception_check_nonnull (void *, jobject);
|
||||
|
||||
extern void android_get_keysym_name (int, char *, size_t);
|
||||
extern void android_wait_event (void);
|
||||
|
|
|
@ -178,7 +178,7 @@ Alternatively, return nil if the clipboard is empty. */)
|
|||
bytes);
|
||||
data = (*android_java_env)->GetByteArrayElements (android_java_env,
|
||||
bytes, NULL);
|
||||
android_exception_check_1 (bytes);
|
||||
android_exception_check_nonnull (data, bytes);
|
||||
|
||||
string = make_unibyte_string ((char *) data, length);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue