diff options
| author | Po Lu | 2023-03-01 09:30:01 +0800 |
|---|---|---|
| committer | Po Lu | 2023-03-01 09:30:01 +0800 |
| commit | f8a2619d981b7ba578378e592b878f08f29e4ba9 (patch) | |
| tree | dd251e37ca11afa32c820d8685bd01525ebc321a /src | |
| parent | 49d5aa365793ee7d71d42e506160f5bb4341b476 (diff) | |
| download | emacs-f8a2619d981b7ba578378e592b878f08f29e4ba9.tar.gz emacs-f8a2619d981b7ba578378e592b878f08f29e4ba9.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/android.c | 27 | ||||
| -rw-r--r-- | src/android.h | 1 | ||||
| -rw-r--r-- | src/androidselect.c | 2 |
3 files changed, 27 insertions, 3 deletions
diff --git a/src/android.c b/src/android.c index 001fa867d9c..3bccaab041a 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -4370,6 +4370,8 @@ android_query_tree (android_window handle, android_window *root_return, | |||
| 4370 | shorts | 4370 | shorts |
| 4371 | = (*android_java_env)->GetShortArrayElements (android_java_env, array, | 4371 | = (*android_java_env)->GetShortArrayElements (android_java_env, array, |
| 4372 | NULL); | 4372 | NULL); |
| 4373 | android_exception_check_nonnull (shorts, array); | ||
| 4374 | |||
| 4373 | for (i = 1; i < nelements; ++i) | 4375 | for (i = 1; i < nelements; ++i) |
| 4374 | children[i] = shorts[i]; | 4376 | children[i] = shorts[i]; |
| 4375 | 4377 | ||
| @@ -4422,6 +4424,7 @@ android_get_geometry (android_window handle, | |||
| 4422 | = (*android_java_env)->GetIntArrayElements (android_java_env, | 4424 | = (*android_java_env)->GetIntArrayElements (android_java_env, |
| 4423 | window_geometry, | 4425 | window_geometry, |
| 4424 | NULL); | 4426 | NULL); |
| 4427 | android_exception_check_nonnull (ints, window_geometry); | ||
| 4425 | 4428 | ||
| 4426 | *x_return = ints[0]; | 4429 | *x_return = ints[0]; |
| 4427 | *y_return = ints[1]; | 4430 | *y_return = ints[1]; |
| @@ -4477,7 +4480,7 @@ android_translate_coordinates (android_window src, int x, | |||
| 4477 | /* Obtain the coordinates from the array. */ | 4480 | /* Obtain the coordinates from the array. */ |
| 4478 | ints = (*android_java_env)->GetIntArrayElements (android_java_env, | 4481 | ints = (*android_java_env)->GetIntArrayElements (android_java_env, |
| 4479 | coordinates, NULL); | 4482 | coordinates, NULL); |
| 4480 | android_exception_check_1 (coordinates); | 4483 | android_exception_check_nonnull (ints, coordinates); |
| 4481 | 4484 | ||
| 4482 | *root_x = ints[0]; | 4485 | *root_x = ints[0]; |
| 4483 | *root_y = ints[1]; | 4486 | *root_y = ints[1]; |
| @@ -5302,6 +5305,26 @@ android_exception_check_2 (jobject object, jobject object1) | |||
| 5302 | } | 5305 | } |
| 5303 | } | 5306 | } |
| 5304 | 5307 | ||
| 5308 | /* Check for JNI problems based on the value of OBJECT. | ||
| 5309 | |||
| 5310 | Signal out of memory if OBJECT is NULL. OBJECT1 means the | ||
| 5311 | same as in `android_exception_check_1'. | ||
| 5312 | |||
| 5313 | This function is useful when checking for errors from JNI | ||
| 5314 | functions that do not set exceptions on failure, such as | ||
| 5315 | `GetIntArrayElements'. */ | ||
| 5316 | |||
| 5317 | void | ||
| 5318 | android_exception_check_nonnull (void *object, jobject object1) | ||
| 5319 | { | ||
| 5320 | if (object) | ||
| 5321 | return; | ||
| 5322 | |||
| 5323 | if (object1) | ||
| 5324 | ANDROID_DELETE_LOCAL_REF (object1); | ||
| 5325 | |||
| 5326 | memory_full (0); | ||
| 5327 | } | ||
| 5305 | 5328 | ||
| 5306 | 5329 | ||
| 5307 | 5330 | ||
| @@ -5656,7 +5679,7 @@ android_query_battery (struct android_battery_state *status) | |||
| 5656 | 5679 | ||
| 5657 | longs = (*android_java_env)->GetLongArrayElements (android_java_env, | 5680 | longs = (*android_java_env)->GetLongArrayElements (android_java_env, |
| 5658 | array, NULL); | 5681 | array, NULL); |
| 5659 | android_exception_check_1 (array); | 5682 | android_exception_check_nonnull (longs, array); |
| 5660 | 5683 | ||
| 5661 | status->capacity = longs[0]; | 5684 | status->capacity = longs[0]; |
| 5662 | status->charge_counter = longs[1]; | 5685 | status->charge_counter = longs[1]; |
diff --git a/src/android.h b/src/android.h index 65389f84e6a..806be4f9954 100644 --- a/src/android.h +++ b/src/android.h | |||
| @@ -86,6 +86,7 @@ extern jstring android_build_jstring (const char *); | |||
| 86 | extern void android_exception_check (void); | 86 | extern void android_exception_check (void); |
| 87 | extern void android_exception_check_1 (jobject); | 87 | extern void android_exception_check_1 (jobject); |
| 88 | extern void android_exception_check_2 (jobject, jobject); | 88 | extern void android_exception_check_2 (jobject, jobject); |
| 89 | extern void android_exception_check_nonnull (void *, jobject); | ||
| 89 | 90 | ||
| 90 | extern void android_get_keysym_name (int, char *, size_t); | 91 | extern void android_get_keysym_name (int, char *, size_t); |
| 91 | extern void android_wait_event (void); | 92 | extern void android_wait_event (void); |
diff --git a/src/androidselect.c b/src/androidselect.c index 2d8f14bb90d..3947ab99166 100644 --- a/src/androidselect.c +++ b/src/androidselect.c | |||
| @@ -178,7 +178,7 @@ Alternatively, return nil if the clipboard is empty. */) | |||
| 178 | bytes); | 178 | bytes); |
| 179 | data = (*android_java_env)->GetByteArrayElements (android_java_env, | 179 | data = (*android_java_env)->GetByteArrayElements (android_java_env, |
| 180 | bytes, NULL); | 180 | bytes, NULL); |
| 181 | android_exception_check_1 (bytes); | 181 | android_exception_check_nonnull (data, bytes); |
| 182 | 182 | ||
| 183 | string = make_unibyte_string ((char *) data, length); | 183 | string = make_unibyte_string ((char *) data, length); |
| 184 | 184 | ||