fix bug in short to int conversion in StructPointer

This commit is contained in:
David Renshaw 2021-10-05 17:03:57 -04:00
parent c1cb55e277
commit 57dec34d2c
2 changed files with 22 additions and 1 deletions

View file

@ -34,7 +34,7 @@ final class StructPointer{
} }
public static int wordSize(long ref) { public static int wordSize(long ref) {
return (int)dataSize(ref) + (int)ptrCount(ref); return Short.toUnsignedInt(dataSize(ref)) + Short.toUnsignedInt(ptrCount(ref));
} }
public static void setFromStructSize(ByteBuffer buffer, int offset, StructSize size) { public static void setFromStructSize(ByteBuffer buffer, int offset, StructSize size) {

View file

@ -0,0 +1,21 @@
package org.capnproto;
import org.junit.Assert;
import org.junit.Test;
public class StructPointerTest {
@Test
public void testWordSize() {
Assert.assertEquals(
3,
StructPointer.wordSize(0x0001000200000000L));
}
@Test
public void testWordSizeUnderflow() {
Assert.assertEquals(
0x1fffe,
StructPointer.wordSize(0xffffffff00000000L));
}
}