From f8b41e486c3e2e6494cc751364500ce574569f9b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 21 May 2020 17:56:26 +0300 Subject: [PATCH] vm: clone struct item on SETITEM, close #972 It's the same as with APPEND and VALUES. --- pkg/vm/vm.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 6a8b4b1e3..0312f01a6 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1038,6 +1038,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro validateMapKey(key) obj := v.estack.Pop() + val := cloneIfStruct(item) switch t := obj.value.(type) { // Struct and Array items have their underlying value as []StackItem. @@ -1048,7 +1049,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro panic("SETITEM: invalid index") } v.estack.updateSizeRemove(arr[index]) - arr[index] = item + arr[index] = val v.estack.updateSizeAdd(arr[index]) case *MapItem: if i := t.Index(key.value); i >= 0 { @@ -1056,8 +1057,8 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } else if len(t.value) >= MaxArraySize { panic("too big map") } - t.Add(key.value, item) - v.estack.updateSizeAdd(item) + t.Add(key.value, val) + v.estack.updateSizeAdd(val) default: panic(fmt.Sprintf("SETITEM: invalid item type %s", t))