mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 13:37:25 +00:00
Correct calculation of vector element size (#5831)
Number of elements on the stack shouldn't affect the calculation of ElemWidth(). Variable 'start' needs to be subtracted from the loop variable 'i' to make indexing zero-based. There is an additional unit test to pack nested vectors. Size of the packed buffer *without* this fix is 798 and only 664 bytes *with* the fix.
This commit is contained in:
@@ -2885,6 +2885,17 @@ void FlexBuffersTest() {
|
||||
// And from FlexBuffer back to JSON:
|
||||
auto jsonback = jroot.ToString();
|
||||
TEST_EQ_STR(jsontest, jsonback.c_str());
|
||||
|
||||
slb.Clear();
|
||||
slb.Vector([&]() {
|
||||
for (int i = 0; i < 130; ++i) slb.Add(static_cast<uint8_t>(255));
|
||||
slb.Vector([&]() {
|
||||
for (int i = 0; i < 130; ++i) slb.Add(static_cast<uint8_t>(255));
|
||||
slb.Vector([] {});
|
||||
});
|
||||
});
|
||||
slb.Finish();
|
||||
TEST_EQ(slb.GetSize(), 664);
|
||||
}
|
||||
|
||||
void FlexBuffersDeprecatedTest() {
|
||||
|
||||
Reference in New Issue
Block a user