Skip to content

Commit

Permalink
vm: produce better error for ROLL with wrong index
Browse files Browse the repository at this point in the history
Current VM implementation doesn't return errors for many operations, so the
only way to handle it here is to check for NULL. Refs. #96.
  • Loading branch information
roman-khimov committed Aug 31, 2019
1 parent c96be81 commit 428e789
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ func (v *VM) execute(ctx *Context, op Instruction) {
panic("negative stack item returned")
}
if n > 0 {
v.estack.Push(v.estack.RemoveAt(n))
e := v.estack.RemoveAt(n)
if e == nil {
panic("bad index")
}
v.estack.Push(e)
}

case DROP:
Expand Down

0 comments on commit 428e789

Please sign in to comment.