Repository navigation
Round struct sizes up to their alignment - #2
Merged
Merged
Conversation
joejo-unity
approved these changes
Aug 10, 2026
joejo-unity
left a comment
Collaborator
There was a problem hiding this comment.
The fuzzing job may need to have a longer timeout? Otherwise, LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The FlatBuffers spec requires a struct's size to be a multiple of its alignment, so consecutive struct vector elements stay aligned.
flatcdoes this viaPadLastField; FlatSharp pads between fields but never rounds up the total. A struct whose last field is narrower than its alignment serializes short. This is fine at the end of a table where the vtable absorbs it, but in an array of structs every element after the first lands at the wrong offset.The fix is one line after the field loop in
ValueStructTypeModelandStructTypeModel.inlineSizefeedsPhysicalLayout, the serialize/parse slices,MaxInlineSizeand the emitted[StructLayout]size, so it propagates from there.Tests
12 struct instances across 5 schemas change size, updated the matching test expectations and schema doc comments. The two
PoorlyAlignedtests asserted asize (5) is not a multiple of the alignment (4)error; at 8 bytes that no longer throws, so both became round-trips.All tests passed locally (excluding tests without a Mac arm64 target).
csproj
Modified for Unity compatibility, do not upstream.