diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-08-10 04:40:25 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-08-10 04:40:25 +0200 |
commit | f3632ee82dc00fe51ea4e04bb79325c67bcdca39 (patch) | |
tree | ec12a285ef5ce9ae72bc1405ae321f3b9740817c | |
parent | m (diff) | |
download | sha3sum-f3632ee82dc00fe51ea4e04bb79325c67bcdca39.tar.gz sha3sum-f3632ee82dc00fe51ea4e04bb79325c67bcdca39.tar.bz2 sha3sum-f3632ee82dc00fe51ea4e04bb79325c67bcdca39.tar.xz |
fix java-c-jni sigsegv
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | java-c-jni/SHA3.c | 13 |
2 files changed, 16 insertions, 9 deletions
@@ -7,15 +7,18 @@ # # [GNU All Permissive License] +C_OPTIMISE=-O6 +JAVA_OPTIMISE=-O + LIB_EXT=so JAVAC=javac JAVADIRS=-s "java" -d "bin/java" -cp "java" -JAVAFLAGS=-Xlint -O +JAVAFLAGS=-Xlint $(JAVA_OPTIMISE) JAVA_FLAGS=$(JAVADIRS) $(JAVAFLAGS) # NB! Do not forget to test against -O0, -O4 to -O6 is not safe -CFLAGS=-W{all,extra} -pedantic -O6 +CFLAGS=-W{all,extra} -pedantic $(C_OPTIMISE) CPPFLAGS= LDFLAGS= C_FLAGS=$(CFLAGS) $(CPPFLAGS) $(LDFLAGS) @@ -23,15 +26,16 @@ C_FLAGS=$(CFLAGS) $(CPPFLAGS) $(LDFLAGS) JNI_C_INCLUDE=-I$${JAVA_HOME}/include JNI_C_FLAGS=$(JNI_INCLUDE) -fPIC -shared JNI_JAVADIRS=-s "java-c-jni" -d "bin/java-c-jni" -cp "java-c-jni" -JNI_JAVAFLAGS=-Xlint -O +JNI_JAVAFLAGS=-Xlint $(JAVA_OPTIMISE) JNI_JAVA_FLAGS=$(JNI_JAVADIRS) $(JNI_JAVAFLAGS) - JAVA_CLASSES = $(shell find "java" | grep '\.java$$' | sed -e 's_^_bin/_g' -e 's_java$$_class_g') C_OBJS = $(shell find "c" | grep '\.h$$' | sed -e 's_^_bin/_g' -e 's_h$$_o_g') C_BINS = bin/c/sha3sum JNI_CLASSES = $(shell find "java-c-jni" | grep '\.java$$' | sed -e 's_^_bin/_g' -e 's_java$$_class_g') + + all: java c 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; |