[kaffe] String problem / NullPointerException in KJC

Guilhem Lavaux guilhem.lavaux at free.fr
Thu Jul 3 12:28:01 PDT 2003


I forgot to forward the reply to the mailing list...

On Thursday 03 July 2003 18:42, Guilhem Lavaux wrote:
> On Thursday 03 July 2003 17:10, Helmer Krämer wrote:
> > On Wed, 2 Jul 2003 21:08:05 +0100
> > Guilhem Lavaux <guilhem.lavaux at free.fr> wrote:
> >
> > Hi,
> >
> > > I then wondered if this may be caused by the original Boyer-Moore
> > > algorithm implemented in Kaffe and so I tried to shutdown it: the
> > > problem disappeared. Looking at the code I am a little surprised of one
> > > statement which can cause an "overread" of a string buffer:
> > >
> > >         k= n - m+1;
> > >        ^^^^^^^^^^^^^^
> > >         for ( i=offset; i <= k; ) {
> > >           if ( memcmp( &a[i], p, m2) == 0 )
> > >                 return i;
> > >           i += bs[ (unsigned char)a[i+m] ];
> > > 					^^^^^^^^^^^
> > >        }
> > >
> > > It seems that it is possible the algorithm wants to fetch a[n+1] and
> > > this may cause the NullPointerException. Changing i<=k in i<k solves
> > > the problem for KJC although I do know if it is the right to do because
> > > I am not really aware of the Boyer-Moore algorithm.
> > >
> > > Any comments ? I included the log of KJC during the compilation of the
> > > core classes.
> >
> > i think even i<k is still wrong ;) n Is the length of the string
> > and m is the length of the pattern, so the largest possible start
> > index of the pattern is n-m-1. Therefore it should be n-m-1 and
> > <=k or n-m and <k, shouldn't it?
> >
> > Greetings,
> > Helmer
>
> Yes that's right ! At first, I did not want to change much things as I was
> not understanding the algorithm but I have a look at it again and with
> k=n-m and i<k it should work without problems.
>
> Guilhem.





More information about the kaffe mailing list