diff --git a/pkg/vm/context.go b/pkg/vm/context.go index c6440c9b6..09c0ceaf5 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -85,6 +85,9 @@ func (c *Context) NextIP() int { // Jump unconditionally moves the next instruction pointer to the specified location. func (c *Context) Jump(pos int) { + if pos < 0 || pos > len(c.prog) { + panic("instruction offset is out of range") + } c.nextip = pos } @@ -95,9 +98,6 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) { var err error c.ip = c.nextip - if c.ip < 0 { - return 0, nil, errors.New("invalid instruction offset") - } if c.ip >= len(c.prog) { return opcode.RET, nil, nil }