From f5d1277bfd0983970296a4fa8dbf035ba902b008 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 10 Aug 2021 15:31:16 +0300 Subject: [PATCH] vm: do not copy parameter Signed-off-by: Evgeniy Stratonikov --- pkg/vm/context.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/vm/context.go b/pkg/vm/context.go index af20090cc..e682cda1b 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -97,9 +97,9 @@ func (c *Context) NextIP() int { return c.nextip } -// Next returns the next instruction to execute with its parameter if any. After -// its invocation the instruction pointer points to the instruction being -// returned. +// Next returns the next instruction to execute with its parameter if any. +// The parameter is not copied and shouldn't be written to. After its invocation +// the instruction pointer points to the instruction being returned. func (c *Context) Next() (opcode.Opcode, []byte, error) { var err error @@ -171,8 +171,7 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) { if err != nil { return instr, nil, err } - parameter := make([]byte, numtoread) - copy(parameter, c.prog[c.nextip:c.nextip+numtoread]) + parameter := c.prog[c.nextip : c.nextip+numtoread] c.nextip += numtoread return instr, parameter, nil }