Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.

Commit cd6afd9

Browse files
Connor Kuehlnpmccallum
authored andcommitted
Don't reference unaligned packed field
This will be an error some day. warning: reference to packed field is unaligned --> src/certs/sev/cert/mod.rs:176:47 | 176 | 1 => PublicKey::try_from(unsafe { &value.v1.body.data.key }), | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unaligned_references)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #82523 <rust-lang/rust#82523> = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) Also bump the minimum stable compiler. The addr_of! macro was introduced in 1.51.0. Signed-off-by: Connor Kuehl <[email protected]>
1 parent 695bf2d commit cd6afd9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- nightly
2222
- beta
2323
- stable
24-
- 1.42.0
24+
- 1.51.0
2525
profile:
2626
- name: debug
2727
- name: release

src/certs/sev/cert/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ impl TryFrom<&Certificate> for PublicKey<Usage> {
173173

174174
fn try_from(value: &Certificate) -> Result<Self> {
175175
match value.version() {
176-
1 => PublicKey::try_from(unsafe { &value.v1.body.data.key }),
176+
1 => PublicKey::try_from(unsafe {
177+
&std::ptr::addr_of!(value.v1.body.data.key).read_unaligned()
178+
}),
177179
_ => Err(ErrorKind::InvalidInput.into()),
178180
}
179181
}

0 commit comments

Comments
 (0)