vm: fail if DROP has no argument
This commit is contained in:
parent
729b7a0b24
commit
6e4014547d
2 changed files with 19 additions and 0 deletions
|
@ -439,6 +439,9 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
|||
}
|
||||
|
||||
case DROP:
|
||||
if v.estack.Len() < 1 {
|
||||
panic("stack is too small")
|
||||
}
|
||||
v.estack.Pop()
|
||||
|
||||
case EQUAL:
|
||||
|
|
|
@ -803,6 +803,22 @@ func TestOVERgood(t *testing.T) {
|
|||
assert.Equal(t, 3, vm.estack.Len())
|
||||
}
|
||||
|
||||
func TestDROPBadNoItem(t *testing.T) {
|
||||
prog := makeProgram(DROP)
|
||||
vm := load(prog)
|
||||
vm.Run()
|
||||
assert.Equal(t, true, vm.state.HasFlag(faultState))
|
||||
}
|
||||
|
||||
func TestDROPGood(t *testing.T) {
|
||||
prog := makeProgram(DROP)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(1)
|
||||
vm.Run()
|
||||
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||
assert.Equal(t, 0, vm.estack.Len())
|
||||
}
|
||||
|
||||
func TestXDROPbadNoitem(t *testing.T) {
|
||||
prog := makeProgram(XDROP)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue