Error while using strcat() in JNI

Deshmukh, Pramod Pramod_Deshmukh at securecomputing.com
Wed Jun 3 22:12:24 UTC 2009


Below is the c program which is called by java. Java passed string object to
this method which is converted to char *. When I print using printf()
function it prints the string (char *), but strcat() does not like char *.

 

Attached is the .h file the same. Please help me. Also I have attached the
.log file

 

Thanks in Advance.

 

--Pramod

 

==================================================================

#include "nativetest.h" /*double quotes tells it to search current
directory*/

#include <string.h>

 

JNIEXPORT jstring JNICALL Java_nativetest_sayHello

  (JNIEnv *env, jobject thisobject, jstring p_data, jstring p_salt)

 

{

                printf("Inside C program \n");

                printf("=================================\n");

 

                char *cmdOpenSsl;

                jboolean iscopy;

 

                char* cDesc = strdup((*env)->GetStringUTFChars(env, p_data,
&iscopy));

                printf("cDesc ==  %s ", cDesc);

 

                cmdOpenSsl = "echo -n ";

                strcat(cmdOpenSsl, cDesc);

                printf("cmdOpenSsl == %s", cmdOpenSsl);

 

                return p_data;

}

 

-=====================================================

 

Error is

 

cDesc ==  Pramod

#

# An unexpected error has been detected by HotSpot Virtual Machine:

#

#  SIGBUS (0xa) at pc=0x2814bf62, pid=85946, tid=0x8054000

#

# Java VM: Java HotSpot(TM) Server VM (diablo-1.5.0_07-b01 mixed mode)

# Problematic frame:

# C  [libc.so.6+0xa5f62]  strcat+0x1a

#

# An error report file with more information is saved as hs_err_pid85946.log

#

# If you would like to submit a bug report, please write

# a letter to freebsd-java at FreeBSD.org mailing list

#

Abort trap: 6 (core dumped)

 

 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: nativetest.h
Type: application/octet-stream
Size: 457 bytes
Desc: nativetest.h
Url : http://lists.freebsd.org/pipermail/freebsd-java/attachments/20090603/c3706258/nativetest.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hs_err_pid85946.log
Type: application/octet-stream
Size: 6408 bytes
Desc: hs_err_pid85946.log
Url : http://lists.freebsd.org/pipermail/freebsd-java/attachments/20090603/c3706258/hs_err_pid85946.obj


More information about the freebsd-java mailing list