@@ -252,9 +252,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
252
252
Align :: from_bytes ( align) . unwrap ( ) ,
253
253
MiriMemoryKind :: Rust . into ( )
254
254
) ;
255
+ // We just allocated this, the access cannot fail
255
256
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 ( ) ;
258
259
this. write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
259
260
}
260
261
"__rust_dealloc" => {
@@ -494,15 +495,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
494
495
Align :: from_bytes ( 1 ) . unwrap ( ) ,
495
496
MiriMemoryKind :: Env . into ( ) ,
496
497
) ;
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
+
506
507
if let Some ( var) = this. machine . env_vars . insert (
507
508
name. to_owned ( ) ,
508
509
value_copy,
@@ -839,7 +840,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
839
840
} ,
840
841
"GetSystemInfo" => {
841
842
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" ) ;
843
851
// Initialize with `0`.
844
852
this. memory_mut ( ) . get_mut ( system_info_ptr. alloc_id ) ?
845
853
. write_repeat ( tcx, system_info_ptr, 0 , system_info. layout . size ) ?;
0 commit comments