[kaffe] String problem / NullPointerException in KJC

Guilhem Lavaux guilhem.lavaux@free.fr
Thu Jul 3 12:28:01 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=E4mer wrote:
> > On Wed, 2 Jul 2003 21:08:05 +0100
> > Guilhem Lavaux <guilhem.lavaux@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 o=
ne
> > > statement which can cause an "overread" of a string buffer:
> > >
> > >         k=3D n - m+1;
> > >        ^^^^^^^^^^^^^^
> > >         for ( i=3Doffset; i <=3D k; ) {
> > >           if ( memcmp( &a[i], p, m2) =3D=3D 0 )
> > >                 return i;
> > >           i +=3D 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<=3Dk in i<k solves
> > > the problem for KJC although I do know if it is the right to do becau=
se
> > > 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
> > <=3Dk 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=3Dn-m and i<k it should work without problems.
>
> Guilhem.