Re: SIGSEGV issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux