vm: do not pop items in OVER

This commit is contained in:
Evgenii Stratonikov 2019-09-18 14:24:42 +03:00
parent 7cd69ea8e2
commit 4a8be486f0
2 changed files with 3 additions and 6 deletions

View file

@ -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:

View file

@ -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) {