-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix misalignment of small structs in a Vector (C++) #7883
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Can we add an annotated flatbuffer to this alignment test? (See docs). This would be useful to see how the data is laid out in the binary which is important. Ideally we would check in an annotated binary before this fix, so we can show how it gets fix (sort of like how you did in your PR description). |
@dbaileychess thanks for the feedback, I'll look to the annotated flatbuffer things and will fix the build errors that I see on some compilers/OSs. |
b8c86c3
to
011fc51
Compare
I should admit this alignment_test looks a little bit convoluted, because I decided to extend the original test that essentially broke the alignment ..., maybe it make sense to extract alignment_test related files to a separate folder? |
This pull request is stale because it has been open 3 weeks with no activity. Please comment or label |
@dbaileychess I don't think that I can add Thanks! |
This pull request is stale because it has been open 3 weeks with no activity. Please comment or label |
Added the issue, because I've realized that I posted a fix for the "non-existent" issue so people maybe not looking at it as a bug: Closes: #8024 |
Sorry for the delay, was out on paternity leave. |
Hooray! Thanks for accepting and congrats! |
* Rare fix: kick fix test * Rare fix: real fix * Rare fix: separate test * Rare fix: remove comments * Rare fix: updates * Rare fix: less * Rare fix: size_t switch to uoffset_t * Rare fix: swap exp/val * Rare fix: add annotated before/after * Rare fix: remove unnecessary changes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
* Rare fix: kick fix test * Rare fix: real fix * Rare fix: separate test * Rare fix: remove comments * Rare fix: updates * Rare fix: less * Rare fix: size_t switch to uoffset_t * Rare fix: swap exp/val * Rare fix: add annotated before/after * Rare fix: remove unnecessary changes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
This pulls in the functional fix in google/flatbuffers#7883 This fixes creation of vectors of structs with the "raw" flatbuffer API. I observed this when writing tests for the static flatbuffer API and discovering a discrepancy where the static flatbuffer API behaved correctly and the existing API did not. Change-Id: I124192b7f23cad4ae9b50366921ddb4e6a2590cd Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
* Rare fix: kick fix test * Rare fix: real fix * Rare fix: separate test * Rare fix: remove comments * Rare fix: updates * Rare fix: less * Rare fix: size_t switch to uoffset_t * Rare fix: swap exp/val * Rare fix: add annotated before/after * Rare fix: remove unnecessary changes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
* Rare fix: kick fix test * Rare fix: real fix * Rare fix: separate test * Rare fix: remove comments * Rare fix: updates * Rare fix: less * Rare fix: size_t switch to uoffset_t * Rare fix: swap exp/val * Rare fix: add annotated before/after * Rare fix: remove unnecessary changes --------- Co-authored-by: Derek Bailey <derekbailey@google.com>
Fixes the bug that was introduced by: #7520
Closes: #8024
The issue:
Small structs that are less than
uoffset_t
in size without any special alignment rules may result in a broken Vector layout that reads back with different values.Example of the flatbuffers:
now if a Vector of just 3 values of
JustSmallStruct: { 2, 1 }, { 3, 1 }, { 4, 1 }
is created withFlatBufferBuilder::CreateVectorOfStructs<T>()
we get this binary Vector that is when read back get zeros in the firstJustSmallStruct
item:More confusing is that
FlatBufferBuilder::CreateUninitializedVectorOfStructs<T>()
method doesn't have this behavior and not adding "2 bytes zeros" before writing the vectorlen
element.The Fix:
This MR makes
builder.CreateVectorOfStructs<T>()
behaves correctly for small structures vectors and it's now the same as theFlatBufferBuilder::CreateUninitializedVectorOfStructs<T>()
.