mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +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:
@@ -1522,7 +1522,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
||||
Type vector_type = FBT_KEY;
|
||||
// Check bit widths and types for all elements.
|
||||
for (size_t i = start; i < stack_.size(); i += step) {
|
||||
auto elem_width = stack_[i].ElemWidth(buf_.size(), i + prefix_elems);
|
||||
auto elem_width =
|
||||
stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems);
|
||||
bit_width = (std::max)(bit_width, elem_width);
|
||||
if (typed) {
|
||||
if (i == start) {
|
||||
|
||||
Reference in New Issue
Block a user