diff options
author | Eric Seppanen <eds@reric.net> | 2021-07-16 12:22:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 21:22:02 +0200 |
commit | 67538b64ea1b90a0d01e4f6ebd45713ec03c9222 (patch) | |
tree | edde7c4ec2744b0221eebaea2e40125d9d441076 /src/codegen/mod.rs | |
parent | 14a8d29baa1da364c6f33de42c4048ed573b06ed (diff) |
Allow explicit padding (#2060)
If a struct needs to be serialized in its native format (padding bytes
and all), for example writing it to a file or sending it on the network,
then explicit padding fields are necessary, as anything reading the
padding bytes of a struct may lead to Undefined Behavior.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6f8a451a..515ebf17 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1797,6 +1797,14 @@ impl CodeGenerator for CompInfo { (), ); } + // Check whether an explicit padding field is needed + // at the end. + if let Some(comp_layout) = layout { + fields.extend( + struct_layout + .add_tail_padding(&canonical_name, comp_layout), + ); + } } if is_opaque { |