@@ -252,9 +252,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
252252 Align :: from_bytes ( align) . unwrap ( ) ,
253253 MiriMemoryKind :: Rust . into ( )
254254 ) ;
255+ // We just allocated this, the access cannot fail
255256 this. memory_mut ( )
256- . get_mut ( ptr. alloc_id ) ?
257- . write_repeat ( tcx, ptr, 0 , Size :: from_bytes ( size) ) ? ;
257+ . get_mut ( ptr. alloc_id ) . unwrap ( )
258+ . write_repeat ( tcx, ptr, 0 , Size :: from_bytes ( size) ) . unwrap ( ) ;
258259 this. write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
259260 }
260261 "__rust_dealloc" => {
@@ -494,15 +495,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
494495 Align :: from_bytes ( 1 ) . unwrap ( ) ,
495496 MiriMemoryKind :: Env . into ( ) ,
496497 ) ;
497- {
498- let alloc = this. memory_mut ( ) . get_mut ( value_copy. alloc_id ) ? ;
499- alloc. write_bytes ( tcx, value_copy, & value) ? ;
500- let trailing_zero_ptr = value_copy. offset (
501- Size :: from_bytes ( value. len ( ) as u64 ) ,
502- tcx,
503- ) ? ;
504- alloc. write_bytes ( tcx, trailing_zero_ptr, & [ 0 ] ) ? ;
505- }
498+ // We just allocated these, so the write cannot fail.
499+ let alloc = this. memory_mut ( ) . get_mut ( value_copy. alloc_id ) . unwrap ( ) ;
500+ alloc. write_bytes ( tcx, value_copy, & value) . unwrap ( ) ;
501+ let trailing_zero_ptr = value_copy. offset (
502+ Size :: from_bytes ( value. len ( ) as u64 ) ,
503+ tcx,
504+ ) . unwrap ( ) ;
505+ alloc. write_bytes ( tcx, trailing_zero_ptr, & [ 0 ] ) . unwrap ( ) ;
506+
506507 if let Some ( var) = this. machine . env_vars . insert (
507508 name. to_owned ( ) ,
508509 value_copy,
@@ -839,7 +840,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
839840 } ,
840841 "GetSystemInfo" => {
841842 let system_info = this. deref_operand ( args[ 0 ] ) ?;
842- let system_info_ptr = system_info. ptr . to_ptr ( ) ?;
843+ let ( system_info_ptr, align) = system_info. to_scalar_ptr_align ( ) ;
844+ let system_info_ptr = this. memory ( )
845+ . check_ptr_access (
846+ system_info_ptr,
847+ system_info. layout . size ,
848+ align,
849+ ) ?
850+ . expect ( "cannot be a ZST" ) ;
843851 // Initialize with `0`.
844852 this. memory_mut ( ) . get_mut ( system_info_ptr. alloc_id ) ?
845853 . write_repeat ( tcx, system_info_ptr, 0 , system_info. layout . size ) ?;
0 commit comments