From 925652c13037838dbd9b756344340db77c9ab669 Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Mon, 15 Feb 2016 12:15:42 +0200 Subject: java: Fix array size when converting from Java to C++ Signed-off-by: Petre Eftime --- java/jni/BluetoothGattCharacteristic.cxx | 6 +----- java/jni/BluetoothGattDescriptor.cxx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/java/jni/BluetoothGattCharacteristic.cxx b/java/jni/BluetoothGattCharacteristic.cxx index 6d21e0e6..61cceda4 100644 --- a/java/jni/BluetoothGattCharacteristic.cxx +++ b/java/jni/BluetoothGattCharacteristic.cxx @@ -72,11 +72,7 @@ jboolean Java_tinyb_BluetoothGattCharacteristic_writeValue(JNIEnv *env, jobject jbyte *native_array = env->GetByteArrayElements(argValue, &is_copy); jsize native_array_length = env->GetArrayLength(argValue); - std::vector array(native_array_length); - for (int i = 0; i < native_array_length; ++i) - { - array.push_back(native_array[i]); - } + std::vector array(native_array, native_array + native_array_length); return obj_gatt_char->write_value(array) ? JNI_TRUE : JNI_FALSE; } diff --git a/java/jni/BluetoothGattDescriptor.cxx b/java/jni/BluetoothGattDescriptor.cxx index 091e0be9..02b04dbe 100644 --- a/java/jni/BluetoothGattDescriptor.cxx +++ b/java/jni/BluetoothGattDescriptor.cxx @@ -69,11 +69,7 @@ jboolean Java_tinyb_BluetoothGattDescriptor_writeValue(JNIEnv *env, jobject obj, jbyte *native_array = env->GetByteArrayElements(argValue, &is_copy); jsize native_array_length = env->GetArrayLength(argValue); - std::vector array(native_array_length); - for (int i = 0; i < native_array_length; ++i) - { - array.push_back(native_array[i]); - } + std::vector array(native_array, native_array + native_array_length); return obj_gatt_desc->write_value(array) ? JNI_TRUE : JNI_FALSE; } -- cgit v1.2.3