Skip to content

Commit

Permalink
Fixed JVM crash due to EXCEPTION_ACCESS_VIOLATION
Browse files Browse the repository at this point in the history
"The function get_java_var_long() in SerialImp.c casts the Java-long-value to a long in case of type == 'J'. But Java-Long is 64 bit and C-long is only 32 bit. Later this long is cast to a 64-bit-memory-address -> crash. A possible solution is to return always size_t instead of long."

NeuronRobotics#131
NeuronRobotics#133
NeuronRobotics#135
  • Loading branch information
rssgit committed Mar 5, 2020
1 parent 54dcaa7 commit 66f7640
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/c/include/SerialImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ int translate_parity( JNIEnv *, tcflag_t *, jint );
void system_wait();
void finalize_event_info_struct( struct event_info_struct * );
int read_byte_array( JNIEnv *, jobject *, int, unsigned char *, int, int );
long get_java_var_long( JNIEnv *, jobject, char *, char * );
size_t get_java_var_long( JNIEnv *, jobject, char *, char * );
size_t get_java_var( JNIEnv *, jobject, char *, char * );
jboolean is_interrupted( struct event_info_struct * );
int send_event(struct event_info_struct *, jint, int );
Expand Down
Binary file modified src/main/c/resources/native/windows/x86_32/libNRJavaSerial.dll
Binary file not shown.
Binary file modified src/main/c/resources/native/windows/x86_64/libNRJavaSerial.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main/c/src/SerialImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5075,9 +5075,9 @@ size_t get_java_var( JNIEnv *env, jobject jobj, char *id, char *type ) {
return (size_t) get_java_var_long( env, jobj, id, type );
}

long get_java_var_long( JNIEnv *env, jobject jobj, char *id, char *type )
size_t get_java_var_long( JNIEnv *env, jobject jobj, char *id, char *type )
{
long result = 0;
size_t result = 0;
jclass jclazz = (*env)->GetObjectClass( env, jobj );
jfieldID jfd = (*env)->GetFieldID( env, jclazz, id, type );

Expand All @@ -5092,7 +5092,7 @@ long get_java_var_long( JNIEnv *env, jobject jobj, char *id, char *type )
return result;
}
if ( !strcmp( type, "J" ) ) {
result = (long)( (*env)->GetLongField( env, jobj, jfd ) );
result = (size_t)( (*env)->GetLongField( env, jobj, jfd ) );
} else {
result = (size_t) ( (*env)->GetIntField( env, jobj, jfd ) );
}
Expand Down

0 comments on commit 66f7640

Please sign in to comment.