pool_queue: Add static assert for management_array offset #475
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.
In order for the GNU extension of static initialisation of flexible
array member to work. Care must be taken to check whether the offset of
management_array
is the size of the structure, so that accessing themanagement_array
will be to the allocated static memory following thepool struct. If this assertion fails, accessing management_array might
end of accessing the struct padding inserted by the compiler.
Additional explanation:
Current struct layout
->
= locationmanagement_array
points to (outside the struct)If future modifications are to be added to this data structure, say adding/removing an u8 field. A possible layout will be
->
= locationmanagement_array
points to (inside the struct)In this case,
management_array
points to the struct padding due to the layout ofuvisor_pool_entry_t
being u8. However, the actual management array is located after the paddings (due to struct alignments).The C standard does not make clear requirements on struct paddings, but it would be nice to avoid the grey area and be certain.
See also: http://www.cl.cam.ac.uk/~pes20/cerberus/notes30.pdf Section 3.3