Skip to content

Commit 56a5e49

Browse files
committed
fix bug in Stack::pop_frame
1 parent e7c06b5 commit 56a5e49

File tree

1 file changed

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

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl Stack {
273273
instance: Inst,
274274
) -> Option<(Ip, Sp, Mem0Ptr, Mem0Len, Inst)> {
275275
let (ip, start, changed_instance) = self.frames.pop()?;
276-
let sp = self.values.sp(start);
276+
let sp = self.values.sp_or_dangling(start);
277277
let (mem0, mem0_len, instance) = match changed_instance {
278278
Some(instance) => {
279279
let (mem0, mem0_len) = extract_mem0(store, instance);
@@ -325,9 +325,20 @@ impl ValueStack {
325325
}
326326

327327
fn sp(&mut self, start: usize) -> Sp {
328+
debug_assert!(!self.cells.is_empty());
328329
Sp::new(&mut self.cells, start)
329330
}
330331

332+
fn sp_or_dangling(&mut self, start: usize) -> Sp {
333+
match self.cells.is_empty() {
334+
true => {
335+
debug_assert_eq!(start, 0);
336+
Sp::dangling()
337+
}
338+
false => self.sp(start),
339+
}
340+
}
341+
331342
fn prepare_host_frame<'a>(
332343
&'a mut self,
333344
caller_start: usize,

0 commit comments

Comments
 (0)