@@ -67,18 +67,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
67
67
Align :: from_bytes ( prev_power_of_two ( size) ) . unwrap ( )
68
68
}
69
69
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 > > {
71
71
let this = self . eval_context_mut ( ) ;
72
72
if size == 0 {
73
- Scalar :: null_ptr ( this)
73
+ Ok ( Scalar :: null_ptr ( this) )
74
74
} else {
75
75
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 ( ) ) ? ;
77
77
if zero_init {
78
78
// We just allocated this, the access is definitely in-bounds.
79
79
this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( size as usize ) ) . unwrap ( ) ;
80
80
}
81
- Scalar :: Ptr ( ptr)
81
+ Ok ( Scalar :: Ptr ( ptr) )
82
82
}
83
83
}
84
84
@@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104
104
Ok ( Scalar :: null_ptr ( this) )
105
105
} else {
106
106
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 ( ) ) ? ;
108
108
Ok ( Scalar :: Ptr ( new_ptr) )
109
109
}
110
110
} else {
@@ -331,7 +331,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331
331
"malloc" => {
332
332
let & [ ref size] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
333
333
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 ) ? ;
335
335
this. write_scalar ( res, dest) ?;
336
336
}
337
337
"calloc" => {
@@ -340,7 +340,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
340
340
let len = this. read_scalar ( len) ?. to_machine_usize ( this) ?;
341
341
let size =
342
342
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 ) ? ;
344
344
this. write_scalar ( res, dest) ?;
345
345
}
346
346
"free" => {
@@ -368,7 +368,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
368
368
Size :: from_bytes ( size) ,
369
369
Align :: from_bytes ( align) . unwrap ( ) ,
370
370
MiriMemoryKind :: Rust . into ( ) ,
371
- ) ;
371
+ ) ? ;
372
372
this. write_scalar ( ptr, dest) ?;
373
373
}
374
374
"__rust_alloc_zeroed" => {
@@ -380,7 +380,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
380
380
Size :: from_bytes ( size) ,
381
381
Align :: from_bytes ( align) . unwrap ( ) ,
382
382
MiriMemoryKind :: Rust . into ( ) ,
383
- ) ;
383
+ ) ? ;
384
384
// We just allocated this, the access is definitely in-bounds.
385
385
this. memory . write_bytes ( ptr. into ( ) , iter:: repeat ( 0u8 ) . take ( usize:: try_from ( size) . unwrap ( ) ) ) . unwrap ( ) ;
386
386
this. write_scalar ( ptr, dest) ?;
0 commit comments