Skip to content

Commit 5aee2f9

Browse files
committed
Fix an off-by-one in anyref stack manipulation
With more than two anyref stack arguments we were accidentally storing the anyref values one higher in the stack than intended, so fix this off-by-one by switching up some addition logic.
1 parent 6e3e9d2 commit 5aee2f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/anyref-xform/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,14 @@ impl Transform<'_> {
510510
// Store an anyref at an offset from our function's stack
511511
// pointer frame.
512512
let get_fp = builder.local_get(fp);
513-
next_stack_offset += 1;
514-
let (index, idx_local) = if next_stack_offset == 1 {
513+
let (index, idx_local) = if next_stack_offset == 0 {
515514
(get_fp, fp)
516515
} else {
517516
let rhs = builder.i32_const(next_stack_offset);
518517
let add = builder.binop(BinaryOp::I32Add, get_fp, rhs);
519518
(builder.local_tee(scratch_i32, add), scratch_i32)
520519
};
520+
next_stack_offset += 1;
521521
let store = builder.table_set(self.table, index, local);
522522
let get = builder.local_get(idx_local);
523523
builder.with_side_effects(vec![store], get, Vec::new())

0 commit comments

Comments
 (0)