vm: create an array of false items in NEWARRAY/NEWSTRUCT

This commit is contained in:
Evgenii Stratonikov 2019-09-12 11:24:10 +03:00
parent bafdb916a0
commit 71cfd14b92
2 changed files with 12 additions and 4 deletions

View file

@ -611,7 +611,7 @@ func (v *VM) execute(ctx *Context, op Instruction) {
switch t := item.value.(type) {
case *BigIntegerItem:
n := t.value.Int64()
items := make([]StackItem, n)
items := makeArrayOfFalses(int(n))
v.estack.PushVal(&ArrayItem{items})
case *StructItem:
v.estack.PushVal(&ArrayItem{t.value})
@ -626,7 +626,7 @@ func (v *VM) execute(ctx *Context, op Instruction) {
switch t := item.value.(type) {
case *BigIntegerItem:
n := t.value.Int64()
items := make([]StackItem, n)
items := makeArrayOfFalses(int(n))
v.estack.PushVal(&StructItem{items})
case *ArrayItem:
v.estack.PushVal(&StructItem{t.value})
@ -853,6 +853,14 @@ func (v *VM) execute(ctx *Context, op Instruction) {
}
}
func makeArrayOfFalses(n int) []StackItem {
items := make([]StackItem, n)
for i := range items {
items[i] = &BoolItem{false}
}
return items
}
func init() {
log.SetPrefix("NEO-GO-VM > ")
log.SetFlags(0)

View file

@ -397,7 +397,7 @@ func TestNEWARRAYInteger(t *testing.T) {
vm.Run()
assert.Equal(t, false, vm.state.HasFlag(faultState))
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, &ArrayItem{make([]StackItem, 1)}, vm.estack.Pop().value)
assert.Equal(t, &ArrayItem{[]StackItem{makeStackItem(false)}}, vm.estack.Pop().value)
}
func TestNEWARRAYStruct(t *testing.T) {
@ -437,7 +437,7 @@ func TestNEWSTRUCTInteger(t *testing.T) {
vm.Run()
assert.Equal(t, false, vm.state.HasFlag(faultState))
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, &StructItem{make([]StackItem, 1)}, vm.estack.Pop().value)
assert.Equal(t, &StructItem{[]StackItem{makeStackItem(false)}}, vm.estack.Pop().value)
}
func TestNEWSTRUCTArray(t *testing.T) {