Skip to content

Commit c68956c

Browse files
committed
fix bug in ValueStack::replace
1 parent 498e996 commit c68956c

File tree

1 file changed

+12
-5
lines changed
  • crates/wasmi/src/engine/executor/handler

1 file changed

+12
-5
lines changed

crates/wasmi/src/engine/executor/handler/state.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ pub struct Sp {
174174

175175
impl Sp {
176176
pub fn new(cells: &mut Vec<UntypedVal>, start: usize) -> Self {
177-
debug_assert!(start < cells.len(), "start = {}, cells.len() = {}", start, cells.len());
177+
debug_assert!(
178+
start < cells.len(),
179+
"start = {}, cells.len() = {}",
180+
start,
181+
cells.len()
182+
);
178183
Self {
179184
value: unsafe { cells.as_mut_ptr().add(start) },
180185
}
@@ -390,8 +395,7 @@ impl ValueStack {
390395
) -> Result<Sp, TrapCode> {
391396
let params_len = callee_params.len();
392397
let params_offset = usize::from(u16::from(callee_params.span().head()));
393-
debug_assert!(params_offset <= len_slots);
394-
debug_assert!(params_offset + usize::from(params_len) <= len_slots);
398+
debug_assert!(usize::from(params_len) <= len_slots);
395399
if len_slots == 0 {
396400
return Ok(Sp::dangling());
397401
}
@@ -401,12 +405,15 @@ impl ValueStack {
401405
if end > self.max_height {
402406
return Err(TrapCode::StackOverflow);
403407
}
404-
self.cells.resize_with(end, UntypedVal::default);
405-
let Some(cells) = self.cells.get_mut(start..end) else {
408+
let Some(cells) = self.cells.get_mut(start..) else {
406409
unsafe { unreachable_unchecked!() }
407410
};
408411
let params_end = params_offset.wrapping_add(usize::from(params_len));
409412
cells.copy_within(params_offset..params_end, 0);
413+
self.cells.resize_with(end, UntypedVal::default);
414+
let Some(cells) = self.cells.get_mut(start..end) else {
415+
unsafe { unreachable_unchecked!() }
416+
};
410417
let locals_start = start.wrapping_add(usize::from(params_len));
411418
cells[locals_start..].fill_with(UntypedVal::default);
412419
let sp = self.sp(start);

0 commit comments

Comments
 (0)