Date: Thu, 4 Jun 2009 14:29:29 +0930 From: Malcolm Kay <malcolm.kay@internode.on.net> To: freebsd-java@freebsd.org Cc: "Deshmukh, Pramod" <Pramod_Deshmukh@securecomputing.com> Subject: Re: Error while using strcat() in JNI Message-ID: <200906041429.29492.malcolm.kay@internode.on.net> In-Reply-To: <5CF2BB5045ED7D44B69F3E63642D693207E63FCF@ICE.scur.com> References: <5CF2BB5045ED7D44B69F3E63642D693207E63FCF@ICE.scur.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 4 Jun 2009 07:08 am, Deshmukh, Pramod wrote: > 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 *. > cmdOpenSsl = "echo -n "; Under modern versions of C literal strings often reside in program memory rather than data memory and therefore cannot be changed. (Memory exception) But even if your compiler places this string in data memory you have made no provision for space to add the suffix. Note also that in C, duplicate literal strings may be implemented as a single string so that if you do manage to change one then the other will also (mysteriously) change. So you need something like: char *cmdOpenSsl; cDesc=strdup(....); cmdOpenSsl=malloc(strlen("echo -n ")+strlen(cDesc)+1); strcpy(cmdOpenSsl,"echo -n "); strcat(cmdOpenSsl,cDesc); The problem would appear to have nothing to do with java. > > > Attached is the .h file the same. Please help me. Also I have > attached the .log file > > > > Thanks in Advance. > > > > --Pramod > Best of luck, Malcolm
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906041429.29492.malcolm.kay>