From 4a8be486f01f1990d0357ddaadb2cbe09a85c2b3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 18 Sep 2019 14:24:42 +0300 Subject: [PATCH] vm: do not pop items in OVER --- pkg/vm/vm.go | 7 +------ pkg/vm/vm_test.go | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index a523642d5..2bed4fb6c 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -408,15 +408,10 @@ func (v *VM) execute(ctx *Context, op Instruction) { } case OVER: - b := v.estack.Pop() - if b == nil { - panic("no top-level element found") - } - a := v.estack.Peek(0) + a := v.estack.Peek(1) if a == nil { panic("no second element found") } - v.estack.Push(b) v.estack.Push(a) case PICK: diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 3856d9d2a..ac9dbe89e 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -920,6 +920,8 @@ func TestOVERbadNoitem(t *testing.T) { vm.estack.PushVal(1) vm.Run() assert.Equal(t, true, vm.state.HasFlag(faultState)) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, makeStackItem(1), vm.estack.Pop().value) } func TestOVERbadNoitems(t *testing.T) {