On Feb 13, 2008, at 11:59 AM, Nikolas Lotz wrote:
hi timothy,
i frequently fetch arrays of structures, which looks something like
this:
--- snip -------------------------------------------------------
public class Foo extends Structure {
public int bar = 0;
public static Structure[] getArray(Pointer p, int size) {
Foo obj = new Foo();
obj.useMemory(p);
obj.read();
return obj.toArray(size);
}
}
--- /snip ------------------------------------------------------
everything works fine, but when there are no items to fetch i get a
'division by zero'.
The argument to Structure.toArray(int) must be greater than zero.
this is actually a 'modulo by zero' in the class
'com.sun.jna.Structure' in line 770. am i doing something wrong or
should
there be a check for 'fieldAlignment' like in the snippet below ?
--- snip -------------------------------------------------------
if ((fieldAlignment != 0) && ((calculatedSize % fieldAlignment) !=
0)) {
[...]
}
--- /snip ------------------------------------------------------
Field alignments will always be greater than or equal to "1"; I don't
know how you would get a zero. Please put together a JUnit test which
exhibits the error.