diff options
author | Petre Eftime <[email protected]> | 2016-02-15 12:15:42 +0200 |
---|---|---|
committer | Petre Eftime <[email protected]> | 2016-02-15 12:15:42 +0200 |
commit | 925652c13037838dbd9b756344340db77c9ab669 (patch) | |
tree | 17e4b26412ec3fb95e9e814261f1deb5d6d2f82d | |
parent | 9e1a0a24cd4f46463dd67aaee17384e258f36c0a (diff) |
java: Fix array size when converting from Java to C++
Signed-off-by: Petre Eftime <[email protected]>
-rw-r--r-- | java/jni/BluetoothGattCharacteristic.cxx | 6 | ||||
-rw-r--r-- | 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<unsigned char> array(native_array_length); - for (int i = 0; i < native_array_length; ++i) - { - array.push_back(native_array[i]); - } + std::vector<unsigned char> 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<unsigned char> array(native_array_length); - for (int i = 0; i < native_array_length; ++i) - { - array.push_back(native_array[i]); - } + std::vector<unsigned char> array(native_array, native_array + native_array_length); return obj_gatt_desc->write_value(array) ? JNI_TRUE : JNI_FALSE; } |