From d6b6ca048533b164775ec3c46ef141146bd8db07 Mon Sep 17 00:00:00 2001 From: Nik Reiman Date: Mon, 11 Apr 2016 18:46:32 +0200 Subject: [PATCH 1/2] Malloc allocates in bytes, not num elements --- src/main/cpp/ShortArray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cpp/ShortArray.cpp b/src/main/cpp/ShortArray.cpp index bae5531..8e8adb9 100644 --- a/src/main/cpp/ShortArray.cpp +++ b/src/main/cpp/ShortArray.cpp @@ -101,7 +101,7 @@ void ShortArray::set(JNIEnv *env, jshortArray data) { if (_num_elements == 0) { _data = NULL; } else { - _data = (short *)malloc(_num_elements); + _data = (short *)malloc(_num_elements * sizeof(jshort)); env->GetShortArrayRegion(data, 0, (jsize)_num_elements, (jshort *)_data); } } From 5936ca4405fdeb186907658435d0c3f498951028 Mon Sep 17 00:00:00 2001 From: Nik Reiman Date: Mon, 11 Apr 2016 18:48:19 +0200 Subject: [PATCH 2/2] ShortArray::get() should return a non-const short* Not sure why we decided to go with const void* for the initial API, it makes no sense (and also, the data is mutable). --- src/main/cpp/ShortArray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cpp/ShortArray.h b/src/main/cpp/ShortArray.h index 6c6ef5c..a15a6fc 100644 --- a/src/main/cpp/ShortArray.h +++ b/src/main/cpp/ShortArray.h @@ -64,7 +64,7 @@ class EXPORT ShortArray { /** * @brief Get a pointer to the natively stored data */ - const void* get() const { return _data; } + short* get() const { return _data; } /** * @brief Convert data to a Java byte[] array