From 5b4aff5edf70ac07a6934e882d293346a759e5a9 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 20 Jan 2021 21:52:39 +1000 Subject: [PATCH] Android: Fix possible reference overflow when scanning --- .../app/src/cpp/android_progress_callback.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/android/app/src/cpp/android_progress_callback.cpp b/android/app/src/cpp/android_progress_callback.cpp index aafff1e0f..36efb3583 100644 --- a/android/app/src/cpp/android_progress_callback.cpp +++ b/android/app/src/cpp/android_progress_callback.cpp @@ -37,16 +37,16 @@ void AndroidProgressCallback::SetTitle(const char* title) { Assert(title); JNIEnv* env = AndroidHelpers::GetJNIEnv(); - jstring text_jstr = env->NewStringUTF(title); - env->CallVoidMethod(m_java_object, m_set_title_method, text_jstr); + LocalRefHolder text_jstr(env, env->NewStringUTF(title)); + env->CallVoidMethod(m_java_object, m_set_title_method, text_jstr.Get()); } void AndroidProgressCallback::SetStatusText(const char* text) { Assert(text); JNIEnv* env = AndroidHelpers::GetJNIEnv(); - jstring text_jstr = env->NewStringUTF(text); - env->CallVoidMethod(m_java_object, m_set_status_text_method, text_jstr); + LocalRefHolder text_jstr(env, env->NewStringUTF(text)); + env->CallVoidMethod(m_java_object, m_set_status_text_method, text_jstr.Get()); } void AndroidProgressCallback::SetProgressRange(u32 range) @@ -59,7 +59,10 @@ void AndroidProgressCallback::SetProgressRange(u32 range) void AndroidProgressCallback::SetProgressValue(u32 value) { + const u32 old_value = m_progress_value; BaseProgressCallback::SetProgressValue(value); + if (old_value == m_progress_value) + return; JNIEnv* env = AndroidHelpers::GetJNIEnv(); env->CallVoidMethod(m_java_object, m_set_progress_value_method, static_cast(value)); @@ -89,22 +92,22 @@ void AndroidProgressCallback::ModalError(const char* message) { Assert(message); JNIEnv* env = AndroidHelpers::GetJNIEnv(); - jstring message_jstr = env->NewStringUTF(message); - env->CallVoidMethod(m_java_object, m_modal_error_method, message_jstr); + LocalRefHolder message_jstr(env, env->NewStringUTF(message)); + env->CallVoidMethod(m_java_object, m_modal_error_method, message_jstr.Get()); } bool AndroidProgressCallback::ModalConfirmation(const char* message) { Assert(message); JNIEnv* env = AndroidHelpers::GetJNIEnv(); - jstring message_jstr = env->NewStringUTF(message); - return env->CallBooleanMethod(m_java_object, m_modal_confirmation_method, message_jstr); + LocalRefHolder message_jstr(env, env->NewStringUTF(message)); + return env->CallBooleanMethod(m_java_object, m_modal_confirmation_method, message_jstr.Get()); } void AndroidProgressCallback::ModalInformation(const char* message) { Assert(message); JNIEnv* env = AndroidHelpers::GetJNIEnv(); - jstring message_jstr = env->NewStringUTF(message); - env->CallVoidMethod(m_java_object, m_modal_information_method, message_jstr); + LocalRefHolder message_jstr(env, env->NewStringUTF(message)); + env->CallVoidMethod(m_java_object, m_modal_information_method, message_jstr.Get()); }