Skip to content

Commit d257159

Browse files
committed
fix UB in a test
also add an explicit test for the fact that a Option<WidePtr> has padding when it is None
1 parent 55f602f commit d257159

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/tests/mem.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,20 @@ fn offset_of_addr() {
773773
#[test]
774774
fn const_maybe_uninit_zeroed() {
775775
// Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term)
776+
777+
// It is crucial that this type has no padding!
776778
#[repr(C)]
777779
struct Foo {
778-
a: Option<&'static str>,
780+
a: Option<&'static u8>,
779781
b: Bar,
780782
c: f32,
783+
_pad: u32,
781784
d: *const u8,
782785
}
786+
783787
#[repr(C)]
784788
struct Bar(usize);
789+
785790
struct FooPtr(*const Foo);
786791
unsafe impl Sync for FooPtr {}
787792

0 commit comments

Comments
 (0)