From f3632ee82dc00fe51ea4e04bb79325c67bcdca39 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 10 Aug 2013 04:40:25 +0200 Subject: fix java-c-jni sigsegv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- java-c-jni/SHA3.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'java-c-jni') diff --git a/java-c-jni/SHA3.c b/java-c-jni/SHA3.c index 666a7c6..f9dd01d 100644 --- a/java-c-jni/SHA3.c +++ b/java-c-jni/SHA3.c @@ -28,7 +28,7 @@ #define null 0 -#define byte jbyte +#define byte char #define boolean long #define true 1 #define false 0 @@ -713,18 +713,21 @@ JNIEXPORT void JNICALL Java_SHA3_initialise(JNIEnv* env, jclass class, jint bitr JNIEXPORT void JNICALL Java_SHA3_update(JNIEnv* env, jclass class, jbyteArray msg, jint msglen) { (void) class; - - update((*env)->GetByteArrayElements(env, msg, 0), msglen); + if ((msg != 0) && (msglen != 0)) + update((byte*)((*env)->GetByteArrayElements(env, msg, 0)), msglen); } JNIEXPORT jbyteArray JNICALL Java_SHA3_digest(JNIEnv* env, jclass class, jbyteArray msg, jint msglen) { - byte* rcn; + jbyte* rcn; jbyteArray rcj; (void) class; - rcn = digest((*env)->GetByteArrayElements(env, msg, 0), msglen); + if ((msg != 0) && (msglen != 0)) + rcn = (jbyte*)digest((byte*)((*env)->GetByteArrayElements(env, msg, 0)), msglen); + else + rcn = (jbyte*)digest(0, 0); rcj = (*env)->NewByteArray(env, (n + 7) >> 3); (*env)->SetByteArrayRegion(env, rcj, 0, (n + 7) >> 3, rcn); return rcj; -- cgit v1.2.3-70-g09d2