vm: clone struct item on SETITEM, close #972

It's the same as with APPEND and VALUES.
This commit is contained in:
Roman Khimov 2020-05-21 17:56:26 +03:00
parent e07fd4f9f0
commit f8b41e486c

View file

@ -1038,6 +1038,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
validateMapKey(key) validateMapKey(key)
obj := v.estack.Pop() obj := v.estack.Pop()
val := cloneIfStruct(item)
switch t := obj.value.(type) { switch t := obj.value.(type) {
// Struct and Array items have their underlying value as []StackItem. // 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") panic("SETITEM: invalid index")
} }
v.estack.updateSizeRemove(arr[index]) v.estack.updateSizeRemove(arr[index])
arr[index] = item arr[index] = val
v.estack.updateSizeAdd(arr[index]) v.estack.updateSizeAdd(arr[index])
case *MapItem: case *MapItem:
if i := t.Index(key.value); i >= 0 { 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 { } else if len(t.value) >= MaxArraySize {
panic("too big map") panic("too big map")
} }
t.Add(key.value, item) t.Add(key.value, val)
v.estack.updateSizeAdd(item) v.estack.updateSizeAdd(val)
default: default:
panic(fmt.Sprintf("SETITEM: invalid item type %s", t)) panic(fmt.Sprintf("SETITEM: invalid item type %s", t))