[Patch] natString.cc: Some fixes for bounds checking arithmetic.

Dalibor Topic robilad@kaffe.org
Tue Sep 23 17:53:00 GMT 2003


Ralph Loader wrote:
> libgcj contains many places where checking of array index arguments
> passed to methods is done incorrectly.
> 
> The attached patch fixes those in natString.cc that it is not difficult
> to write test cases for.

> There are many other instances of incorrect bounds checking that would
> require a 64 bit machine with gigabytes of memory (which I don't have),
> in order to write proper test cases.

I was wondering about a similar thing in kaffe, and it may be saner to 
write the array index argument checking code once in a final class in 
Java and/or a static inline method in C++/function in C and let the 
compiler do the inlining magic.

That way, you'd only need to get the test right once. And having a

public final class ArrayUtils {
   public static final void checkBounds(int off, int array_len, int 
count) throws IndexOutOfBoundException {
     if (off < 0 || count < 0 || .... ) throw new 
IndexOutOfBoundsException(...);
}

and static inline void checkArrayBounds(int off, int array_len, int 
count) accordingly.

what do you think?

cheers,
dalibor topic





More information about the Java-patches mailing list