From 428e789ddc814696ed7e7b46750125be050d5ef8 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 31 Aug 2019 09:04:59 +0300 Subject: [PATCH] vm: produce better error for ROLL with wrong index 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. --- pkg/vm/vm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 19914cce2..eff7dac51 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -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: