File tree 2 files changed +5
-4
lines changed
2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,10 @@ fn main() {
18
18
19
19
// Turns out the discriminant is (currently) stored
20
20
// in the 1st pointer, so the second half is padding.
21
- let c = ( & p as * const mem:: MaybeUninit < E > ) . byte_add ( mem:: size_of :: < & ' static ( ) > ( ) ) as * const u8 ;
21
+ let c = & p as * const _ as * const u8 ;
22
+ let padding_offset = mem:: size_of :: < & ' static ( ) > ( ) ;
22
23
// Read a padding byte.
23
- let _val = * c. add ( 0 ) ;
24
+ let _val = * c. add ( padding_offset ) ;
24
25
//~^ERROR: uninitialized
25
26
}
26
27
}
Original file line number Diff line number Diff line change 1
1
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
2
2
--> tests/fail/uninit/padding-enum.rs:LL:CC
3
3
|
4
- LL | let _val = *c.add(0 );
5
- | ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
4
+ LL | let _val = *c.add(padding_offset );
5
+ | ^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
6
6
|
7
7
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8
8
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
You can’t perform that action at this time.
0 commit comments