@@ -67,18 +67,18 @@ 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 ( & mut self , size : u64 , zero_init : bool , kind : MiriMemoryKind ) -> InterpResult < ' tcx , Scalar < Tag > > {
7171 let this = self . eval_context_mut ( ) ;
7272 if size == 0 {
73- Scalar :: null_ptr ( this)
73+ Ok ( Scalar :: null_ptr ( this) )
7474 } else {
7575 let align = this. min_align ( size, kind) ;
76- let ptr = this. memory . allocate ( Size :: from_bytes ( size) , align, kind. into ( ) ) ;
76+ let ptr = this. memory . allocate ( Size :: from_bytes ( size) , align, kind. into ( ) ) ? ;
7777 if zero_init {
7878 // We just allocated this, the access is definitely in-bounds.
7979 this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( size as usize ) ) . unwrap ( ) ;
8080 }
81- Scalar :: Ptr ( ptr)
81+ Ok ( Scalar :: Ptr ( ptr) )
8282 }
8383 }
8484
@@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104104 Ok ( Scalar :: null_ptr ( this) )
105105 } else {
106106 let new_ptr =
107- this. memory . allocate ( Size :: from_bytes ( new_size) , new_align, kind. into ( ) ) ;
107+ this. memory . allocate ( Size :: from_bytes ( new_size) , new_align, kind. into ( ) ) ? ;
108108 Ok ( Scalar :: Ptr ( new_ptr) )
109109 }
110110 } else {
@@ -331,7 +331,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331331 "malloc" => {
332332 let & [ ref size] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
333333 let size = this. read_scalar ( size) ?. to_machine_usize ( this) ?;
334- let res = this. malloc ( size, /*zero_init:*/ false , MiriMemoryKind :: C ) ;
334+ let res = this. malloc ( size, /*zero_init:*/ false , MiriMemoryKind :: C ) ? ;
335335 this. write_scalar ( res, dest) ?;
336336 }
337337 "calloc" => {
@@ -340,7 +340,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
340340 let len = this. read_scalar ( len) ?. to_machine_usize ( this) ?;
341341 let size =
342342 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 ) ;
343+ let res = this. malloc ( size, /*zero_init:*/ true , MiriMemoryKind :: C ) ? ;
344344 this. write_scalar ( res, dest) ?;
345345 }
346346 "free" => {
@@ -368,7 +368,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
368368 Size :: from_bytes ( size) ,
369369 Align :: from_bytes ( align) . unwrap ( ) ,
370370 MiriMemoryKind :: Rust . into ( ) ,
371- ) ;
371+ ) ? ;
372372 this. write_scalar ( ptr, dest) ?;
373373 }
374374 "__rust_alloc_zeroed" => {
@@ -380,7 +380,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
380380 Size :: from_bytes ( size) ,
381381 Align :: from_bytes ( align) . unwrap ( ) ,
382382 MiriMemoryKind :: Rust . into ( ) ,
383- ) ;
383+ ) ? ;
384384 // We just allocated this, the access is definitely in-bounds.
385385 this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( usize:: try_from ( size) . unwrap ( ) ) ) . unwrap ( ) ;
386386 this. write_scalar ( ptr, dest) ?;
0 commit comments