forked from TrueCloudLab/neoneo-go
Merge pull request #331 from nspcc-dev/vm-fix-things-for-96
This fixes two minor things observed in #96: running VM twice, which leads to instruction execution attempt for VM in FAULT state panicing with nil dereference (it's better to show some error message) Before this patchset: NEO-GO-VM > run NEO-GO-VM > error encountered at instruction 6 (ROLL) NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference FAULT NEO-GO-VM > error encountered at instruction 7 (SETITEM) NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8 After this patchset: NEO-GO-VM > run NEO-GO-VM > error encountered at instruction 6 (ROLL) NEO-GO-VM > bad index FAULT
This commit is contained in:
commit
f9a5ce89da
2 changed files with 13 additions and 12 deletions
|
@ -127,16 +127,13 @@ func (c *VMCLI) handleCommand(cmd string, args ...string) {
|
||||||
fmt.Printf("READY: loaded %d instructions\n", c.vm.Context().LenInstr())
|
fmt.Printf("READY: loaded %d instructions\n", c.vm.Context().LenInstr())
|
||||||
|
|
||||||
case "run":
|
case "run":
|
||||||
|
if len(args) != 0 {
|
||||||
var (
|
var (
|
||||||
method []byte
|
method []byte
|
||||||
params []vm.StackItem
|
params []vm.StackItem
|
||||||
err error
|
err error
|
||||||
start int
|
start int
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) == 0 {
|
|
||||||
c.vm.Run()
|
|
||||||
} else {
|
|
||||||
if isMethodArg(args[0]) {
|
if isMethodArg(args[0]) {
|
||||||
method = []byte(args[0])
|
method = []byte(args[0])
|
||||||
start = 1
|
start = 1
|
||||||
|
@ -146,8 +143,8 @@ func (c *VMCLI) handleCommand(cmd string, args ...string) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
c.vm.LoadArgs(method, params)
|
c.vm.LoadArgs(method, params)
|
||||||
|
}
|
||||||
c.vm.Run()
|
c.vm.Run()
|
||||||
|
|
||||||
case "cont":
|
case "cont":
|
||||||
|
|
|
@ -342,7 +342,11 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
||||||
panic("negative stack item returned")
|
panic("negative stack item returned")
|
||||||
}
|
}
|
||||||
if n > 0 {
|
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:
|
case DROP:
|
||||||
|
|
Loading…
Reference in a new issue