Commit 84ff4da 1 parent b3f4c31 commit 84ff4da Copy full SHA for 84ff4da
File tree 2 files changed +10
-1
lines changed
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 163
163
#![ feature( allow_internal_unstable) ]
164
164
#![ feature( associated_type_bounds) ]
165
165
#![ feature( auto_traits) ]
166
+ #![ feature( cfg_sanitize) ]
166
167
#![ feature( cfg_target_has_atomic) ]
167
168
#![ feature( cfg_target_has_atomic_equal_alignment) ]
168
169
#![ feature( const_fn_floating_point_arithmetic) ]
Original file line number Diff line number Diff line change @@ -683,7 +683,15 @@ pub unsafe fn uninitialized<T>() -> T {
683
683
// SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
684
684
unsafe {
685
685
intrinsics:: assert_uninit_valid :: < T > ( ) ;
686
- MaybeUninit :: uninit ( ) . assume_init ( )
686
+ let mut val = MaybeUninit :: < T > :: uninit ( ) ;
687
+
688
+ // Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on
689
+ // bool, nonnull, and noundef types. But don't do this if we actively want to detect UB.
690
+ if !cfg ! ( any( miri, sanitize = "memory" ) ) {
691
+ val. as_mut_ptr ( ) . write_bytes ( 0x01 , 1 ) ;
692
+ }
693
+
694
+ val. assume_init ( )
687
695
}
688
696
}
689
697
You can’t perform that action at this time.
0 commit comments