mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 02:22:00 +00:00
Always add additional space if no more is available
Change-Id: If08b2d839489d40e977de794b13584fa66ff32c1
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
803f9bba27
commit
c4a3e2f6bd
@@ -198,7 +198,7 @@ func (b *Builder) Prep(size, additionalBytes int) {
|
|||||||
alignSize &= (size - 1)
|
alignSize &= (size - 1)
|
||||||
|
|
||||||
// Reallocate the buffer if needed:
|
// Reallocate the buffer if needed:
|
||||||
for int(b.head) < alignSize+size+additionalBytes {
|
for int(b.head) <= alignSize+size+additionalBytes {
|
||||||
oldBufSize := len(b.Bytes)
|
oldBufSize := len(b.Bytes)
|
||||||
b.growByteBuffer()
|
b.growByteBuffer()
|
||||||
b.head += UOffsetT(len(b.Bytes) - oldBufSize)
|
b.head += UOffsetT(len(b.Bytes) - oldBufSize)
|
||||||
|
|||||||
@@ -21,12 +21,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
flatbuffers "github.com/google/flatbuffers/go"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -479,6 +480,20 @@ func CheckByteLayout(fail func(string, ...interface{})) {
|
|||||||
b.EndVector(2)
|
b.EndVector(2)
|
||||||
check([]byte{2, 0, 0, 0, 2, 1, 0, 0}) // padding
|
check([]byte{2, 0, 0, 0, 2, 1, 0, 0}) // padding
|
||||||
|
|
||||||
|
// test 3b: 11xbyte vector matches builder size
|
||||||
|
|
||||||
|
b = flatbuffers.NewBuilder(12)
|
||||||
|
b.StartVector(flatbuffers.SizeByte, 8, 1)
|
||||||
|
start := []byte{}
|
||||||
|
check(start)
|
||||||
|
for i := 1; i < 12; i++ {
|
||||||
|
b.PrependByte(byte(i))
|
||||||
|
start = append([]byte{byte(i)}, start...)
|
||||||
|
check(start)
|
||||||
|
}
|
||||||
|
b.EndVector(8)
|
||||||
|
check(append([]byte{8, 0, 0, 0}, start...))
|
||||||
|
|
||||||
// test 4: 1xuint16 vector
|
// test 4: 1xuint16 vector
|
||||||
|
|
||||||
b = flatbuffers.NewBuilder(0)
|
b = flatbuffers.NewBuilder(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user