@@ -67,18 +67,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6767 Align :: from_bytes ( prev_power_of_two ( size) ) . unwrap ( )
6868 }
6969
70- fn malloc ( & mut self , size : u64 , zero_init : bool , kind : MiriMemoryKind ) -> Scalar < Tag > {
70+ fn malloc (
71+ & mut self ,
72+ size : u64 ,
73+ zero_init : bool ,
74+ kind : MiriMemoryKind ,
75+ ) -> InterpResult < ' tcx , Scalar < Tag > > {
7176 let this = self . eval_context_mut ( ) ;
7277 if size == 0 {
73- Scalar :: null_ptr ( this)
78+ Ok ( Scalar :: null_ptr ( this) )
7479 } else {
7580 let align = this. min_align ( size, kind) ;
76- let ptr = this. memory . allocate ( Size :: from_bytes ( size) , align, kind. into ( ) ) ;
81+ let ptr = this. memory . allocate ( Size :: from_bytes ( size) , align, kind. into ( ) ) ? ;
7782 if zero_init {
7883 // We just allocated this, the access is definitely in-bounds.
7984 this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( size as usize ) ) . unwrap ( ) ;
8085 }
81- Scalar :: Ptr ( ptr)
86+ Ok ( Scalar :: Ptr ( ptr) )
8287 }
8388 }
8489
@@ -104,7 +109,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104109 Ok ( Scalar :: null_ptr ( this) )
105110 } else {
106111 let new_ptr =
107- this. memory . allocate ( Size :: from_bytes ( new_size) , new_align, kind. into ( ) ) ;
112+ this. memory . allocate ( Size :: from_bytes ( new_size) , new_align, kind. into ( ) ) ? ;
108113 Ok ( Scalar :: Ptr ( new_ptr) )
109114 }
110115 } else {
@@ -331,7 +336,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331336 "malloc" => {
332337 let & [ ref size] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
333338 let size = this. read_scalar ( size) ?. to_machine_usize ( this) ?;
334- let res = this. malloc ( size, /*zero_init:*/ false , MiriMemoryKind :: C ) ;
339+ let res = this. malloc ( size, /*zero_init:*/ false , MiriMemoryKind :: C ) ? ;
335340 this. write_scalar ( res, dest) ?;
336341 }
337342 "calloc" => {
@@ -340,7 +345,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
340345 let len = this. read_scalar ( len) ?. to_machine_usize ( this) ?;
341346 let size =
342347 items. checked_mul ( len) . ok_or_else ( || err_ub_format ! ( "overflow during calloc size computation" ) ) ?;
343- let res = this. malloc ( size, /*zero_init:*/ true , MiriMemoryKind :: C ) ;
348+ let res = this. malloc ( size, /*zero_init:*/ true , MiriMemoryKind :: C ) ? ;
344349 this. write_scalar ( res, dest) ?;
345350 }
346351 "free" => {
@@ -368,7 +373,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
368373 Size :: from_bytes ( size) ,
369374 Align :: from_bytes ( align) . unwrap ( ) ,
370375 MiriMemoryKind :: Rust . into ( ) ,
371- ) ;
376+ ) ? ;
372377 this. write_scalar ( ptr, dest) ?;
373378 }
374379 "__rust_alloc_zeroed" => {
@@ -380,7 +385,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
380385 Size :: from_bytes ( size) ,
381386 Align :: from_bytes ( align) . unwrap ( ) ,
382387 MiriMemoryKind :: Rust . into ( ) ,
383- ) ;
388+ ) ? ;
384389 // We just allocated this, the access is definitely in-bounds.
385390 this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( usize:: try_from ( size) . unwrap ( ) ) ) . unwrap ( ) ;
386391 this. write_scalar ( ptr, dest) ?;
0 commit comments