Fixed a bug in the Java code generation that would generate the wrong identifier in some cases.

Also added a safety check for buffers growing past 2 gigabytes.

Change-Id: I2bca7159f606cf1c08c4391e88ef9b4c8363be06
Tested: With the Java sdk.
This commit is contained in:
Wouter van Oortmerssen
2014-06-17 17:25:57 -07:00
parent 1485180517
commit 41a6d35e74
2 changed files with 4 additions and 2 deletions

View File

@@ -57,7 +57,9 @@ public class FlatBufferBuilder {
ByteBuffer growByteBuffer(ByteBuffer bb) {
byte[] old_buf = bb.array();
int old_buf_size = old_buf.length;
int new_buf_size = old_buf_size * 2;
if ((old_buf_size & 0xC0000000) != 0)
throw new AssertionError("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");
int new_buf_size = old_buf_size << 1;
byte[] new_buf = new byte[new_buf_size];
System.arraycopy(old_buf, 0, new_buf, new_buf_size - old_buf_size, old_buf_size);
ByteBuffer nbb = newByteBuffer(new_buf);