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