Home > Back-end >  Java error collapse, C language is called for help
Java error collapse, C language is called for help

Time:06-10

Wrote a very simple example of Java call C method, but a run will collapse, can't find the problem, turn to the great god,

C language code:
 # include & lt; stdio.h> 
#include
#include
# include "HelloNative. H"
//# define _XOPEN_SOURCE
Env JNIEXPORT jstring JNICALL Java_HelloNative_getPassword (JNIEnv *, jobject c1, jstring STR, jstring salt) {
Char * passwd;
Jstring out=0;
Passwd=crypt (" ABC ", "$6 $p840S0zS $");
If (passwd==NULL) {
Printf (" NULL ");
} else {
Printf (" password: % s \ n ", the passwd);
Out=(* env) - & gt; NewStringUTF (passwd, "utf-8");
}

Return the out;
}


An error is as follows:
[root @ test - 01 TMP] # Java HelloNative
#
# A fatal error has had been detected by the Java Runtime Environment:
#
# SIGSEGV=0 (0 xb) at PC x00007fc905af6acc, pid=61806, tid=0 x00007fc907036700
#
SE # JRE version: the Java (TM) Runtime Environment (8.0 _231 - b11) (build 1.8.0 comes with _231 - b11)
# Java VM: Java HotSpot (TM) 64 - Bit Server VM (25.231 - bl1 mixed mode Linux - amd64 compressed oops)
# Problematic frame:
# V [libjvm. So + 0 x6c5acc] jni_NewStringUTF + 0 x1c
#
# the Core dump written. The Default location:/TMP/Core or Core. 61806
#
# An error report file with more information is saved as:
#/TMP/hs_err_pid61806. Log
#
# If you order a like to submit a bug report, both please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside The Java Virtual Machine in native code.
# See problematic frame for the where to report the bug.
#
Aborted (core dumped)

CodePudding user response:

Here is the C/C + + plate, are you sure send Java problem here right?



CodePudding user response:

Jni here can also, look from inside information, seems to be a string coding utf have a problem

CodePudding user response:

refer to the second floor SuperDay response:
jni here can also, look from inside information, seems to be is a little string coding utf


Crypt function return values may have a problem, don't know what happened, direct printf collapse

CodePudding user response:

The
reference 3 floor footpath crazy _! Response:
Quote: refer to the second floor SuperDay response:

Jni here can also, look from inside information, seems to be is a little string coding utf


Crypt function return values may have a problem, don't know what happened, direct printf collapse

Don't make now, not many people here seem to make, is expected to be solve by himself

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related