This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: SIGSEGV issue
- From: Andrew Haley <aph-gcc at littlepinkcloud dot COM>
- To: "David Sayada" <david dot sayada at hyperms dot com>
- Cc: classpath at gnu dot org, java at gcc dot gnu dot org, "Amnon David" <amnon at hyperms dot com>
- Date: Wed, 29 Aug 2007 12:59:17 +0100
- Subject: Re: SIGSEGV issue
- References: <54a13c720708290439q6a9392f8m4972c4ba82f85540@mail.gmail.com>
David Sayada writes:
> Hi all,
>
> This email is following the last email I sent a few days ago about SIGSEGV
> occurring in a java CNI application compiled with gcj 4.1.2 on a PXA270
> platform.
>
> I have traced the place in the code causing the exception, and please the
> see below the concerning code:
>
> if ( nReadBytes == 0 )
> {
> continue;
> }
>
> for (int i=0; i<nReadBytes; i++)
> {
> info.m_strRequest += (char)info.m_readBuff.get(i);
> }
>
> I have read in some places that using UTF16 can be problematic with CNI.
Not to my knowledge.
> I think that the char cast automatically uses UTF16 instead of
> UTF8.
Java characters are Unicode by definition, so promoting a byte in this
way gets you a 16-bit Unicode Java character. That's perfectly
alright as long as you're sure that your byte is ASCII. It's
certainly not going to cause a SEGV.
> Am I right? Is there a way to write this code without using the
> char cast?
No. This code is grossly inefficient, though: you really ought to be
using StringBuffer.append(char) like this:
RequestBuffer.append((char)info.m_readBuff.get(i));
Andrew.