From 41a6d35e74779eb69ffa9c1b3b8e1c38717d8bcf Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Tue, 17 Jun 2014 17:25:57 -0700 Subject: [PATCH] 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. --- java/flatbuffers/FlatBufferBuilder.java | 4 +++- src/idl_gen_java.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/java/flatbuffers/FlatBufferBuilder.java b/java/flatbuffers/FlatBufferBuilder.java index 44f201bab..c6864223a 100755 --- a/java/flatbuffers/FlatBufferBuilder.java +++ b/java/flatbuffers/FlatBufferBuilder.java @@ -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); diff --git a/src/idl_gen_java.cpp b/src/idl_gen_java.cpp index d68932c9d..554794fae 100755 --- a/src/idl_gen_java.cpp +++ b/src/idl_gen_java.cpp @@ -255,7 +255,7 @@ static void GenStruct(StructDef &struct_def, code += "obj.__init("; code += field.value.type.struct_def->fixed ? "o + bb_pos" - : "__indirect(o + i)"; + : "__indirect(o + bb_pos)"; code += ", bb) : null"; } break;