vm: use Null item as a default value for Array/Struct elements

This commit is contained in:
Evgenii Stratonikov 2020-05-20 16:37:00 +03:00
parent f4fa712440
commit 781def735d
2 changed files with 5 additions and 5 deletions

View file

@ -993,7 +993,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
if n > MaxArraySize {
panic("too long array")
}
typ := BooleanT
typ := AnyT
if op == opcode.NEWARRAYT {
typ = StackItemType(parameter[0])
}
@ -1018,7 +1018,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
if n > MaxArraySize {
panic("too long struct")
}
items := makeArrayOfType(int(n), BooleanT)
items := makeArrayOfType(int(n), AnyT)
v.estack.PushVal(&StructItem{items})
}

View file

@ -1188,7 +1188,7 @@ func TestNEWARRAYArray(t *testing.T) {
prog := makeProgram(opcode.NEWARRAY)
t.Run("ByteArray", getTestFuncForVM(prog, NewArrayItem([]StackItem{}), []byte{}))
t.Run("BadSize", getTestFuncForVM(prog, nil, MaxArraySize+1))
t.Run("Integer", getTestFuncForVM(prog, []StackItem{NewBoolItem(false)}, 1))
t.Run("Integer", getTestFuncForVM(prog, []StackItem{NullItem{}}, 1))
arr := []StackItem{makeStackItem(42)}
t.Run("Array", getTestFuncForVM(prog, arr, arr))
@ -1206,7 +1206,7 @@ func testNEWARRAYIssue437(t *testing.T, i1, i2 opcode.Opcode, appended bool) {
vm := load(prog)
vm.Run()
arr := makeArrayOfType(4, BooleanT)
arr := makeArrayOfType(4, AnyT)
arr[2] = makeStackItem(3)
arr[3] = makeStackItem(4)
if appended {
@ -1247,7 +1247,7 @@ func TestNEWSTRUCT(t *testing.T) {
prog := makeProgram(opcode.NEWSTRUCT)
t.Run("ByteArray", getTestFuncForVM(prog, NewStructItem([]StackItem{}), []byte{}))
t.Run("BadSize", getTestFuncForVM(prog, nil, MaxArraySize+1))
t.Run("Integer", getTestFuncForVM(prog, NewStructItem([]StackItem{NewBoolItem(false)}), 1))
t.Run("Integer", getTestFuncForVM(prog, NewStructItem([]StackItem{NullItem{}}), 1))
arr := []StackItem{makeStackItem(42)}
t.Run("Array", getTestFuncForVM(prog, NewStructItem(arr), NewArrayItem(arr)))